-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: necessary to make one to many bidirectional?
PostPosted: Wed Dec 16, 2009 11:26 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
What if you don't set the many side of the following association? Does hibernate give an error? I read that its best to map the many to one side because it gives better performance, even if you dont need to be able to be able to get the owning object.

Also what if I have the mapping like below but I don't set the owner on the car object before adding it to the set of cars on the user side? will it make it so that you cant call .getCars() and get the newly adding object after persisting?

public class User {
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, mappedBy="user")
Car getCars() { ... }

}

public class Car {
@ManyToOne
@JoinColumn(name="userId")
User getOwner(){ ... }
void setOwner(User user) { }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.