• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic