Hibernate Date Property Explicit Temporal

ID

java.hibernate_date_property_explicit_temporal

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

hibernate, orm

Description

Reports fields of type java.util.Date or java.util.Calendar in @Entity classes that lack a @Temporal annotation. Without @Temporal, the persistence provider cannot determine whether to map the field to a SQL DATE, TIME, or TIMESTAMP column, resulting in provider-dependent behavior.

Rationale

Reliability — The column type may differ between JPA implementations or database dialects, causing data truncation or precision loss.

Remediation

Non-compliant code

@Entity
public class Event {
    private Date startDate; // no @Temporal
}

Compliant code

@Entity
public class Event {
    @Temporal(TemporalType.TIMESTAMP)
    private Date startDate;
}