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

Bug 535998 WLS 12.2.1.2 DOES NOT PROPERLY IMPLEMENT JSR 303 ISSUE #185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sureshbn
Copy link
Contributor

Signed-off-by: Sureshkumar Balakrishnannair [email protected]

@eclipsewebmaster
Copy link

Issue tracker reference:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=535998

1 similar comment
@eclipsewebmaster
Copy link

Issue tracker reference:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=535998

Copy link
Member

@Tomas-Kraus Tomas-Kraus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good.
Just see that you are not using formating rules from project-admin/EclipseLink-Eclipse-Format.xml
It would be good to use them.

@lukasj
Copy link
Member

lukasj commented Jul 27, 2018

I'm not sure this change follows the spec yet. Anyone else is?

@sureshbn
Copy link
Contributor Author

Applied the formatter [EclipseLink-Eclipse-Format.xml] as specified . In this particular case we are not seeing triggering of events anywhere while updating the entity - Thanks

try {
e1.setName(invalidName);
e1.setSurname(invalidName);
em.persist(e1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No em.merge(e1)? The entity is already managed at this point. I ran a quick local test and I don't see EclipseLink calling @PrePersist twice when there are multiple persists for the same managed entity. I can verify that with EclipseLink's implementation as well. Take a look at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist:

   /**
     * INTERNAL:
     * Called only by registerNewObjectForPersist method,
     * and only if newObject is not already registered.
     * Could be overridden in subclasses.
     */

If the object being persisted is already registered, we don't execute the PrePersistEvent.

@@ -342,6 +343,32 @@ public void testTraversableResolverPreventsLoadingOfLazyRelationships() {
assertTrue( "Lazy field should not be instantiated because of validation", !isInstantiated(employee, "projects", project) );
assertTrue( "Lazy field should not be instantiated because of validation", !isInstantiated(employee, "managedProject", project) );
}

public void testPesistWithInvalidAndModifiedBeanData() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a different test than BeanValidationJunitTest.testUpdateWithInvalidData()? They seem to be trying to test the same thing, but testUpdateWithInvalidData doesn't seem to be using callbacks and is instead expecting validation on transaction commit. Is this right?

try {
// Update it with invalid value
beginTransaction(em);
Employee e = em.find(Employee.class, EMPLOYEE_PK);
e.setName(invalidName);
commitTransaction(em);
} catch (RuntimeException e) {

According to 3.6 of the spec:

These lifecycle validation events occur immediately after the point at which all the 
PrePersist, PreUpdate, and PreRemove lifecycle callback method invocations respectively 
have been complete

I'm wondering if this means testUpdateWithInvalidData is wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a javadoc somewhere saying that current behaviour is expected and intended by the spec - prepersist is called on the first persist call and not during transaction commit, so subsequent updates to the entity, is is done here are not validated as some people would expect. I just don't know, where I saw that comment :-/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasj I see! I think there is a misconception then that validation occurs on transaction commit. After reading the spec, it seems pretty clear that validation occurs on the EntityManager operation invocations. However, I searched around online for some examples and it seems transaction commit is being expected by users. Given the comment you found, it certainly sounds like the current spec design has issues that we may want to address in the future.

For example, here is a Hibernate example I found. It seems the example they are using is expecting transaction commit. Perhaps Hibernate is not adhering to the spec? Idk.

@sureshbn
Copy link
Contributor Author

The conclusion here is : the spec need to evolve/clarify for this case and we need to wait up to that time ? , Please help to confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants