UUID not working as GeneratedValue Id with merge
Closed this issue · 2 comments
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)
To Reproduce
Steps/resources to reproduce the behavior:
Update the following EclipseLink test:
- TestUUIDGenerator.testBasicUUIDIdentity_AUTO_Generator()
Change the call to persist
to merge
.
Expected behavior
The merge should be successful.
Basically the same behavior as seen with other generated types (i.e., SEQUENCE).
@rfelcman Thanks for addressing this issue so quickly!
Out of curiosity, did you not update convertDataValueToObjectValue
to also tolerate null
because null
values would not be supported for UUID in the database?
@rfelcman Thanks for addressing this issue so quickly!
Out of curiosity, did you not update
convertDataValueToObjectValue
to also toleratenull
becausenull
values would not be supported for UUID in the database?
It's about similar pattern like some other convertDataValueToObjectValue
implementations. It's about org.eclipse.persistence.internal.sessions.UnitOfWorkImpl#assignSequenceNumber(java.lang.Object, org.eclipse.persistence.descriptors.ClassDescriptor)
and org.eclipse.persistence.internal.descriptors.ObjectBuilder#assignSequenceNumber(java.lang.Object, java.lang.Object, org.eclipse.persistence.internal.sessions.AbstractSession, org.eclipse.persistence.queries.WriteObjectQuery)
calls.