jakartaee / jakartaee/persistence

Explicit opition to truncate the second precision via the global configuration

Open
#1,158 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
267
Forks
78
Avg merge
1d 6h
Merged PRs (30d)
13

Description

#### Description

Jakarta Persistence introduced the `secondPrecision` attribute to the `@Column` annotation, which allows developers to define the fractional seconds precision (e.g., millisecond vs nanosecond) directly on temporal mappings:

```java
@Column(name = "created_at", secondPrecision = 3) // Generates TIMESTAMP(3)
private Instant createdAt;
```

While this annotation works perfectly for static field mappings, the newly introduced programmatic configuration API via `PersistenceConfiguration` (added in JPA 3.2) lacks a native, global setting to apply default fractional second precision across an entire persistence unit.

Without a global setting, developers using programmatic bootstrap configurations must manually apply `@Column(secondPrecision = X)` to every single temporal field to prevent inconsistent database schemas across environments (such as a database defaulting to `TIMESTAMP(6)` vs Hibernate defaulting to `TIMESTAMP(0)`).

#### Proposed Solution

1. Introduce a standardized configuration property constant in `jakarta.persistence.PersistenceConfiguration`.
2. Allow schema generation tools to honor this configuration fallback globally when a field-level `@Column(secondPrecision)` is absent.

```java
// Suggested Configuration Property
public static final String SCHEMA_GENERATION_DEFAULT_SECOND_PRECISION = "jakarta.persistence.schema-generation.default-second-precision";

// Usage Example
var emf = new PersistenceConfiguration()
.name("MyUnit")
.property(PersistenceConfiguration.SCHEMA_GENERATION_DEFAULT_SECOND_PRECISION, 3) // All generated timestamps fall back to TIMESTAMP(3)
.createEntityManagerFactory();
```

#### Additional Context

Adding global alignment ensures predictable schema parity across different persistence providers (e.g., EclipseLink, Hibernate) and mirrors similar global formatting behaviors available in modern data-binding APIs.

Contributor guide

Open the contributing guide

Research direction

Review jakarta.persistence.PersistenceConfiguration, @Column(secondPrecision), and the schema-generation behavior described in the issue. Determine the specification and provider-fallback requirements for a global default, then verify that the proposed property and its behavior are consistently defined. The work is done when the API and fallback semantics are agreed and documented in the relevant project checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.