It's not a secret anymore!*
The moose likes JPA Certification (OCEJPA) and the fly likes JPA2: how to persist data using @MapKeyColumn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "JPA2: how to persist data using @MapKeyColumn" Watch "JPA2: how to persist data using @MapKeyColumn" New topic
Author

JPA2: how to persist data using @MapKeyColumn

Singh Harmeet
Ranch Hand

Joined: Aug 05, 2011
Posts: 115

In my example I have two entities to persist. But when I try to using @MapKeyColumn annotation , I am confused on how to use this annotation and how to persist the data. This is the example that is explained in the "PRO JPA2 book". When I try to run this code it will generate the exception

two entities:-



and :



my service class function



when i try to insert the data using setEmpCabin(...) function , it wil generate the exception



With Regards :-
Harmeet Singh
Bobby Jakachira
Greenhorn

Joined: Jun 01, 2010
Posts: 14
If you haven't sorted this out already, it is highly likely that this section below is the culprit. I would assume that the cabin_id is being persisted before you reach line 3. The reason lies with how you are propagating your transactions.



When you create the employee, you are passing in a department object which, for this to work, should have empCabin already. You are using container-managed transaction in you beans so once the method finishes the transaction will commit. For this to work before line 2, make sure you set the empCabin. Try that and see how it works..


OCPJP, OCEJWCD, OCEJPAD, OCEEJBD
 
wood burning stoves
 
subject: JPA2: how to persist data using @MapKeyColumn
 
Similar Threads
Simple requirement .. but I don't know how!
Simple requirement .. but I don't know how!
problem with @FieldResult, mapping does not seem to work
Hibernate in case of cascade(All,merge,persist)
Secondary table