Saturday Jun 16, 2007

Workaround to get more information for the JPA exception: During synchronization a new object was found through a relationship that was not marked cascade PERSIST.

I was getting a bit frustrated dealing with the JPA exception During synchronization a new object was found through a relationship that was not marked cascade PERSIST. The issue is that the message doesn't display the object in question. I wanted to grab the code and fix this issue, so here is what I did

  • download the persistence source from https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html. I am working with V1 so I used that version.
  • I copied the class I wanted to modify to my unit test area using the same package structure as in the persistence jar file. I am using NetBeans for unit testing so I adjusted the unit test classpath to put the test classpath ahead of the toplink essentials jar file which effectively replaces the class.
  • Looks like this is just a bug where the IllegalStateException thrown in RepeatableUnitOfWork line 115 (as we all know and love) is passing the object, so all that needs to be done is to fix the error message. I found ExceptionLocalizationResource where the error messages are stored and added a parameter to the new_object_found_during_comment message. I changed it to: "During synchronization a new object was found through a relationship that was not marked cascade PERSIST. {0}." This will provide the output of the toString method for the object where EntityManager.persist was not invoked. Since the toString is in the user space, this allows me to add any additional information to help figure out where to add CascadeType or call persist.

After doing this, additional information on which class (and the toString) is now contained within the exception message.

The glassfish tracking issue has been filed as https://glassfish.dev.java.net/issues/show_bug.cgi?id=3254 



Sunday Apr 08, 2007

Blueprints article about using JPA in a web module

I came across this article about using JPA in a web module. Using JPA in a web only module is more difficult than using JPA in EJB because of the differences in the threading models. Using a request scoped managed bean makes things a bit easier as the injection model is similar to EJB. 
About

cwebster

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today