Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

JPA2: how to persist data using @MapKeyColumn

 
Ranch Hand
Posts: 115
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic