Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Validation on preUpdate checks unchanged entities
Validation on preUpdate checks unchanged entities [message #1064228] Tue, 18 June 2013 06:38 Go to next message
Dirk Weil is currently offline Dirk Weil
Messages: 8
Registered: June 2013
Junior Member
EclipseLink JPA validates every loaded entity object when one of them gets updated - even those which are unchanged within the current persistence context.

As far as I understand the specification, only dirty objects (i. e. objects causing the preUpdate) should be validated.

In our case the EclipseLink behaviour is a complete show stopper: For reasons beyond this posting we have objects breaking validation constraints loaded into the entity manager. One of them is then updated to meet the validation constraints. But we cannot store the updated object because of EclipseLink keeps complaining about the others, which are still unchanged.

Is there an option to turn the validation process into regarding changed objects only?

Regards
Dirk
Re: Validation on preUpdate checks unchanged entities [message #1064245 is a reply to message #1064228] Tue, 18 June 2013 07:49 Go to previous messageGo to next message
Dirk Weil is currently offline Dirk Weil
Messages: 8
Registered: June 2013
Junior Member
I just discovered that it is even worse:

EclipseLink validates all loaded entities regardless of any object change: If I execute some query within a transaction, all objects get validated on transaction commit, even if there is no change at all!

Regards
Dirk
Re: Validation on preUpdate checks unchanged entities [message #1064299 is a reply to message #1064245] Tue, 18 June 2013 11:01 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What validation are you doing, and what exact event are you registering for?

The JPA @PreUpdate event is only triggered for objects with changes.


James : Wiki : Book : Blog : Twitter
Re: Validation on preUpdate checks unchanged entities [message #1064442 is a reply to message #1064299] Wed, 19 June 2013 05:47 Go to previous messageGo to next message
Dirk Weil is currently offline Dirk Weil
Messages: 8
Registered: June 2013
Junior Member
I'm using Bean Validation. So I am doing nothing special, especially no explicit registration for any event.

Here is a code snippet reproducing the effect:
    EntityManager entityManager = Persistence.createEntityManagerFactory("unittest").createEntityManager();
    entityManager.getTransaction().begin();
    List<Fragebogen> frageboegen = entityManager.createQuery("select f from Fragebogen f", Fragebogen.class).getResultList();
    entityManager.getTransaction().commit();


Fragebogen is a simple entity class without any lifecycle methods. Thera are no global entity listeners as well.

Due to historic reasons some existing database entries for Fragebogen do not satisfy the bean validation constraints in Fragebogen. The obviously unchanged objects get validated when commit is requested - and validation fails, which causes a transaction abort in the end.

It seems, that in the process of calculating changes at the end of the transaction validation is triggered even on unchanged objects.

If you ask, why there is a transaction anyway: That is because the snippet is reduced to reproduce the error. Our complete code does some updates.

[Updated on: Wed, 19 June 2013 05:49]

Report message to a moderator

Re: Validation on preUpdate checks unchanged entities [message #1065387 is a reply to message #1064442] Tue, 25 June 2013 10:15 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I looked at the code, and it is a bug. Please log the bug and vote for it.

In BeanValidationListener it should be overriding preUpdateWithChanges not preUpdate.


James : Wiki : Book : Blog : Twitter
Previous Topic:How to use eclipselink.batch with em.find()?
Next Topic:How to access Primary Key instance of entity relationship?
Goto Forum:
  


Current Time: Thu Apr 24 11:37:46 EDT 2014

Powered by FUDForum. Page generated in 0.02825 seconds