51 lines
978 B
Plaintext
51 lines
978 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;
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|