36 lines
783 B
Plaintext
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;
|
|
// ...
|
|
}
|
|
----
|