Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Changes from EntityListeners not propagated in commit
Changes from EntityListeners not propagated in commit [message #879136] Wed, 30 May 2012 11:29 Go to next message
Eclipse UserFriend
Hi all,

I have a JPA 2 PreUpdate/PrePersist entity listener class, in which I trim too long strings to avoid database exception. Since I wanted this to work for many classes, I created an annotation and in the listener, I search for fields annotated with this annotation and trim their values using the Reflection API.

The problem is, when I run unit tests checking this functionality, they pass, but when I use it on our Jetty server (version 6.1.24), the values are not trimmed (the listener gets called, the value is trimmed, but Eclipselink ignores this change) and our database throws truncation exceptions.

I tried using direct field set and invoking setter methods as well because I found somewhere that since Eclipselink uses proxies for entities, direct field set might not be recorded.

Is there any way how to get over this problem? Could Eclipselink event listeners help in this situation? I'm using Eclipselink version 2.3.2.v20111125-r10461.

Thanks in advance
Martin
Re: Changes from EntityListeners not propagated in commit [message #879778 is a reply to message #879136] Thu, 31 May 2012 16:37 Go to previous messageGo to next message
Eclipse UserFriend
What are the property differences between the two environments, and did method access work instead of direct field acccess? My guess is that you are using weaving when running in Jetty which might have woven the classes to use change tracking. By using reflection to access the variables directly, you will be bypassing the woven code that notifies change tracking of the change.
In which case your options are to use method access in your reflective calls - this is a generaly requirement when using bytecode weaving - or not use byte code weaving. I believe using weaving is preferable as it adds performance enhancements to the code. It and how to turn it off is described here:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving

Best Regards,
Chris
Re: Changes from EntityListeners not propagated in commit [message #881217 is a reply to message #879778] Mon, 04 June 2012 02:53 Go to previous message
Eclipse UserFriend
Hi Chris,

thank you for the reply. You're correct about the weaving, I'm using dynamic weaving in Jetty. I tried using reflective calls, but without success.

As for the environment differences, the test environment was using JUnit 4 (called by ant), but there was no weaving in the tests. So this might have been the key difference. The rest of properties was the same, since the tests and Jetty were running on the same machine.

However, I managed to fix the issue by using Eclipselink's DescriptorEvents which work perfectly. Anyway, thanks for your help.

Regards,
Martin
Previous Topic:Order of inserting List items
Next Topic:@CascadeOnDelete and DDL generation on PostgreSQL
Goto Forum:
  


Current Time: Tue Jul 08 00:37:53 EDT 2025

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

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

Back to the top