• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Saving associated objects in hibernate one-to-one mapping

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have one-to-one relationship between two objects (EventActivity & Event).

public class EventActivity extends AbstractTrainingActivity
{

@OneToOne(fetch = FetchType.EAGER)
@PrimaryKeyJoinColumn
private Event event;

public Event getEvent() {
return event;
}

public void setEvent(Event event) {
this.event = event;
}

}

when I try to save EventActivity, everything in AbstractTrainingActivity is getting saved but the Event Object is not getting saved.

Is there any way to tell hibernate to save the associated objects in one-to-one mapping ???
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swetha,

You should add the "cascade" attribute to the OneToOne annotation.

Your annotation will then look like:
@OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)

Adding the cascade annotation will persist, update, or delete the aggregated event when you take that action on the EventActivity.

-Shannon
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic