Skip to main content


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 10:38 Go to next message
Dirk Weil is currently offline Dirk WeilFriend
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 11:49 Go to previous messageGo to next message
Dirk Weil is currently offline Dirk WeilFriend
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 15:01 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
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 09:47 Go to previous messageGo to next message
Dirk Weil is currently offline Dirk WeilFriend
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 09: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 14:15 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
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
Re: Validation on preUpdate checks unchanged entities [message #1708570 is a reply to message #1065387] Thu, 17 September 2015 14:22 Go to previous messageGo to next message
Viacheslav Yakunin is currently offline Viacheslav YakuninFriend
Messages: 1
Registered: September 2015
Junior Member
Hello, I am just curious if it was fixed? Because I still see this behaviour in 2.6.0.

Regards
Sla
Re: Validation on preUpdate checks unchanged entities [message #1729381 is a reply to message #1708570] Wed, 13 April 2016 14:20 Go to previous message
Gilberto Caetano de Andrade is currently offline Gilberto Caetano de AndradeFriend
Messages: 45
Registered: July 2009
Member
Unfortunately no! Here is the bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=411013
Please vote for this bug if it is important to you.
Previous Topic:Problems loading attributes from attributes of abstract type
Next Topic:java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(...)
Goto Forum:
  


Current Time: Thu Apr 18 13:04:12 GMT 2024

Powered by FUDForum. Page generated in 0.02665 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top