-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improve detection of entity state #3604
base: main
Are you sure you want to change the base?
Conversation
Hibernate use 0 or user provided positive initial value as seed of integer version. EclipseLink always use 1 as seed of integer version.
@@ -219,13 +218,37 @@ public Object getCompositeIdAttributeValue(Object id, String idAttribute) { | |||
@Override | |||
public boolean isNew(T entity) { | |||
|
|||
if (versionAttribute.isEmpty() | |||
|| versionAttribute.map(Attribute::getJavaType).map(Class::isPrimitive).orElse(false)) { | |||
if (versionAttribute.isEmpty()) { | |||
return super.isNew(entity); | |||
} | |||
|
|||
BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(entity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work when entity
is a proxy?
I'd like an integration test, that ensures it has a proxy an based on that tests the isNew
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why it's related to proxy, could you expand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entity might be a Hibernate proxy. And I basically don't trust any code to properly work with those. Just the normal paranoia after working with JPA to much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not expert of proxy, as far as I know, proxy only take care of accessing lazy attributes and associations, version is not in that case, and this PR only reuse the existing code wrapper.getPropertyValue(it.getName())
to get value of version to refine the logic.
52ee55f
to
61e6d36
Compare
Hibernate use 0 or user provided positive initial value as seed of integer version.
EclipseLink always use 1 as seed of integer version.