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 



Friday May 04, 2007

NetBeans REST support

Given that Java One begins next week, I wanted to mention some really interesting technology which is available in  NetBeans 6.0 (milestone 9 build). This preview release provides the ability to generate REST services based on a set of JPA entity beans, which you can also generate using NetBeans. The REST services are annotated using the annotations proposed in JSR-311 (so this will change by the time the JSR is finalized). JSR 311 removes the need for service developers to use the Servlet or JAX-WS and instead provides a runtime and a set of annotations to handle dispatching of requests to your REST enabled resources. This feature also requires installation of the Sun Web Developer Pack which contains Phobos (JavaScript application server), JMaki, and of course the RESTful web services supported.

The wizard determines the set of entity beans available in a project and allows a set of beans to be selected and exposed as resources. In addition to generating the rest resource code, the wizard generates a converter layer which provides the ability to marshal and unmarshal to and from the wire protocol. Currently, the converters are using custom XML to serialize data; however, JSON and ATOM publishing protocol are also being considered. Finally, the converter layer translates object references (such as JPA references) into URI references. All the code generated by NetBeans is freely editable (no guarded blocks) and only relies on the JSR-311 annotations.


Accompanying the wizard is the ability to generate a test client to exercise the generated resources. The test client supports interaction with resource collections as well as individual resources through GET, PUT, POST, and DELETE (depending on the options available via the resources). The test client is generated locall and uses XHR for communicating with the resources, which should mimic most common architectures.

This is best to see in action, check out the video

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