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

UUID not working as GeneratedValue Id in some cases #24925

Closed
njr-11 opened this issue Apr 4, 2023 · 6 comments · Fixed by #27892
Closed

UUID not working as GeneratedValue Id in some cases #24925

njr-11 opened this issue Apr 4, 2023 · 6 comments · Fixed by #27892
Assignees
Labels
bug This bug is not present in a released version of Open Liberty in:JPA release bug This bug is present in a released version of Open Liberty release:24004 team:Blizzard

Comments

@njr-11
Copy link
Contributor

njr-11 commented Apr 4, 2023

Describe the bug

Jakarta Persistence 3.1 added the ability to have a UUID be the id and to also be generated. In some cases such as the following, where strategy = GenerationType.UUID or strategy is omitted (defaulting to AUTO), an IllegalArgumentException is being raised when trying to save an entity for the first time (when it starts out without an id, needing it generated).

    @GeneratedValue(strategy = GenerationType.UUID)
    @Id
    public UUID id;
java.lang.IllegalArgumentException: Source object is not an instance of java.util.UUID
	at org.eclipse.persistence.mappings.converters.UUIDConverter.convertObjectValueToDataValue(UUIDConverter.java:46)
	at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.getFieldValue(AbstractDirectMapping.java:790)
	at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.valueFromObject(AbstractDirectMapping.java:1202)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromObject(ObjectBuilder.java:3156)
	at org.eclipse.persistence.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(MergeManager.java:1062)
	at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:575)
	at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:324)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3641)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:402)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3601)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:644)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:622)

Steps to Reproduce

Using the latest Open Liberty code, update the following test classes to switch Long and long and SEQUENCE to UUID:
https://github.com/OpenLiberty/open-liberty/blob/integration/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web/Order.java
https://github.com/OpenLiberty/open-liberty/tree/integration/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web

Then run the following test bucket:
./gradlew io.openliberty.data.internal_fat_jpa:buildandrun

A single failure is reported, from DataJPATestServlet.testGeneratedKey, which reports the aforementioned IllegalArgumentException as the cause.

Expected behavior
It should be possible to save/merge the entity without the id value, and the UUID value should be generated automatically.

Diagnostic information:

Additional context
Add any other context about the problem here.

@njr-11 njr-11 added bug This bug is not present in a released version of Open Liberty in:JPA labels Apr 4, 2023
@edwinquaihoi
Copy link

Any outlook on this issue, seems a pretty fundamental one?

@Riva-Tholoor-Philip Riva-Tholoor-Philip self-assigned this Feb 3, 2024
@Riva-Tholoor-Philip
Copy link
Contributor

Created an EclipseLink issue to bring the fix in EclipseLink. Issue #2086

@tkburroughs tkburroughs added the release bug This bug is present in a released version of Open Liberty label Mar 6, 2024
@tkburroughs
Copy link
Member

Since the problem has been accepted and fixed in EclipseLink, I've added release bug label so this will be documented in release notes when included in open liberty.

@Riva-Tholoor-Philip
Copy link
Contributor

Working on bringing the changes in EclipseLink to Open Liberty

@Riva-Tholoor-Philip
Copy link
Contributor

As PR# 27872 is merged , we are closing this issue

@njr-11
Copy link
Contributor Author

njr-11 commented Mar 11, 2024

Good work fixing the bug. We should keep this issue open until the Jakarta Data tests that discovered it are re-enabled. I created pull #27892 for that.

@njr-11 njr-11 reopened this Mar 11, 2024
saumyapandyaa pushed a commit to saumyapandyaa/open-liberty that referenced this issue Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This bug is not present in a released version of Open Liberty in:JPA release bug This bug is present in a released version of Open Liberty release:24004 team:Blizzard
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants