• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic