• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

EJB 3.0 - Error while persisting one-one unidirectional relation

 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have 2 tables, EMPLOYEE and ADDRESS. Table EMPLOYEE has ADDRESSID column which has a foreign key relationship with ADDRESS whose primary key is ADDRESSID. Using EJB3.0 java persisatance API I wanted to implement one-to-one unidirectional relationship. Hence I created 2 entity classes, Employee and Address. In the Employee class I putting below the relevant code:


In the Address class, there is no code to access the Employee.

I have created a session bean which tries to create an employee along with an Address. Putting the relevant code below:


As mentioned above, error is being thrown at em.persist(emp);. The error is



I am unable to make out anything from the exception stack trace. Any help in this would be greatly appreciated.
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satya,

I think your problem comes from the cascadeType.
You've got to mark your OneToOne with a cascade type at least PERSIST.
If you don't, you'll have an error of type:

"During synchronization a new object was found through a relationship that was not marked cascade PERSIST."

Can you tell me if this corrects your problem ?

Beno�t
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Thanks so much. @OneToOne(cascade={CascadeType.ALL}) solved the problem.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic