rspec/rules/S3363/java/rule.adoc
2021-04-28 16:49:39 +02:00

36 lines
783 B
Plaintext

Using a ``++type="timestamp"++`` column as the primary key of a table is slightly risky. Two threads could create new objects in the table close enough in sequence for them to both have the same timestamp. Alternately, this could happen during a daylight savings time change. Instead, use a numeric value as the ``++@Id++``.
This rule raises an issue when a time or date-related class is annotated with ``++@Id++``.
== Noncompliant Code Example
----
public class Person {
@Id
@Type(type="timestamp")
private Date birthDate; // Noncompliant
private String lastName;
// ...
}
----
== Compliant Solution
----
public class Person {
@Id
@GeneratedValue
int id;
@Type(type="timestamp")
private Date birthDate;
private String lastName;
// ...
}
----