Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EclipseLink disallows @Version attribute of type java.time.LocalDateTime #2343

Closed
anija-anil opened this issue Jan 13, 2025 · 1 comment · Fixed by #2347
Closed

EclipseLink disallows @Version attribute of type java.time.LocalDateTime #2343

anija-anil opened this issue Jan 13, 2025 · 1 comment · Fixed by #2347
Assignees

Comments

@anija-anil
Copy link
Contributor

Section 2.5 of the Jakarta Persistence 3.2 specification requires support for Version attributes that are of type

java.time.LocalDateTime,

The version must be of one of the following basic types:

int, Integer, short, Short, long, Long, or

java.time.LocalDateTime, java.time.Instant, or java.sql.Timestamp.

However, when I try to use an entity,

@Entity
public class County {
    @Version
    public LocalDateTime lastUpdated;

    @Id
    public String name;

    ...

it fails with,

jakarta.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 5.0.0-B05.v202412161836-e4245e29fa3355029f10c42ea5546c73683dd504): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [persistence_service_pu-2] failed.
Internal Exception: Exception [EclipseLink-7168] (Eclipse Persistence Services - 5.0.0-B05.v202412161836-e4245e29fa3355029f10c42ea5546c73683dd504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [lastUpdated] of type [class java.time.LocalDateTime] on the entity class [class test.jakarta.data.jpa.web.County] is not valid for a version property. The following types are supported: int, Integer, short, Short, long, Long, Timestamp.
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:2157)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2133)
	at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactoryImpl(PersistenceProvider.java:424)
	at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:388)
	at com.ibm.wsspi.persistence.internal.PersistenceServiceUnitImpl.<init>(PersistenceServiceUnitImpl.java:91)
	at com.ibm.wsspi.persistence.internal.PersistenceServiceImpl.createPersistenceServiceUnit(PersistenceServiceImpl.java:64)
	at com.ibm.wsspi.persistence.internal.DatabaseStoreImpl.createPersistenceServiceUnit(DatabaseStoreImpl.java:350)
	at ...
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 5.0.0-B05.v202412161836-e4245e29fa3355029f10c42ea5546c73683dd504): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [persistence_service_pu-2] failed.
Internal Exception: Exception [EclipseLink-7168] (Eclipse Persistence Services - 5.0.0-B05.v202412161836-e4245e29fa3355029f10c42ea5546c73683dd504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [lastUpdated] of type [class java.time.LocalDateTime] on the entity class [class test.jakarta.data.jpa.web.County] is not valid for a version property. The following types are supported: int, Integer, short, Short, long, Long, Timestamp.
	at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:233)
	... 14 more
Caused by: Exception [EclipseLink-7168] (Eclipse Persistence Services - 5.0.0-B05.v202412161836-e4245e29fa3355029f10c42ea5546c73683dd504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [lastUpdated] of type [class java.time.LocalDateTime] on the entity class [class test.jakarta.data.jpa.web.County] is not valid for a version property. The following types are supported: int, Integer, short, Short, long, Long, Timestamp.
	at org.eclipse.persistence.exceptions.ValidationException.invalidTypeForVersionAttribute(ValidationException.java:1175)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.VersionAccessor.process(VersionAccessor.java:129)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor.processMappingAccessors(MetadataDescriptor.java:1542)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.processMappingAccessors(ClassAccessor.java:1658)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processMappingAccessors(EntityAccessor.java:1240)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:699)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1919)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:599)
	at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:640)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2054)
	... 12 more

Also, I just tried @Version on a java.time.Instant attribute and it is also rejected, so that needs to be fixed as well.

Note that the error message doesn't indicate LocalDateTime or Instant as supported types, even though the Persistence 3.2 specification requires it.

@Tomas-Kraus Tomas-Kraus self-assigned this Jan 17, 2025
Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Jan 17, 2025
… type java.time.LocalDateTime

Signed-off-by: Tomáš Kraus <[email protected]>
Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Jan 17, 2025
@Tomas-Kraus
Copy link
Member

Yes, this was missing in EclipseLink. Fixed main branch to satisfy JPA 3.2 requirements for versions.

Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Jan 22, 2025
Tomas-Kraus added a commit that referenced this issue Jan 22, 2025
…ime.LocalDateTime

Signed-off-by: Tomáš Kraus <[email protected]>
Tomas-Kraus added a commit that referenced this issue Jan 22, 2025
Tomas-Kraus added a commit that referenced this issue Jan 22, 2025
Signed-off-by: Tomáš Kraus <[email protected]>
Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Jan 22, 2025
Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Jan 22, 2025
Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Jan 22, 2025
rfelcman pushed a commit that referenced this issue Feb 4, 2025
…time.LocalDateTime - code refactoring (#2349)

Signed-off-by: Tomáš Kraus <[email protected]>
rfelcman added a commit to rfelcman/eclipselink that referenced this issue Feb 4, 2025
…f type java.time.LocalDateTime - code refactoring plus additional unit test

Signed-off-by: Radek Felcman <[email protected]>
rfelcman added a commit to rfelcman/eclipselink that referenced this issue Feb 4, 2025
…f type java.time.LocalDateTime - code refactoring plus additional unit test

Signed-off-by: Radek Felcman <[email protected]>
rfelcman added a commit that referenced this issue Feb 4, 2025
…ime.LocalDateTime - code refactoring plus additional unit test (#2359)


Signed-off-by: Radek Felcman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants