61 lines
1.1 KiB
Plaintext
61 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,java]
|
|
----
|
|
public class Person {
|
|
|
|
@Id
|
|
@Type(type="timestamp")
|
|
private Date birthDate; // Noncompliant
|
|
|
|
private String lastName;
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
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)
|
|
|
|
=== Message
|
|
|
|
Use a numeric "@id" column instead.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
* primary: ``++@id++`` annotation
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|