Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsChanges from EntityListeners not propagated in commit
https://www.eclipse.org/forums/index.php/mv/msg/357013/879136/#msg_879136
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]]>Martin Ledvinka2012-05-30T15:29:01-00:00Re: Changes from EntityListeners not propagated in commit
https://www.eclipse.org/forums/index.php/mv/msg/357013/879778/#msg_879778
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]]>Chris Delahunt2012-05-31T20:37:35-00:00Re: Changes from EntityListeners not propagated in commit
https://www.eclipse.org/forums/index.php/mv/msg/357013/881217/#msg_881217
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.