• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2189
  • Last Modified:

Hibernate one to many array list

I am using hibernate 3, If a student has an array of courses (bi directional), how to write hbm.XML and database schema.
public class Student{
        private Long sid;
        private String name;
        private List<Course> courses;
....
}
 
public lass Course{
         private Long cid;
         private String courseName;
         private Student student;
....
}

Open in new window

0
JianJunShen
Asked:
JianJunShen
  • 2
4 Solutions
 
mahomeCommented:
0
 
JianJunShenAuthor Commented:
I also found following comments in the link mentioned below:

http://tadtech.blogspot.com/2007/02/hibernate-when-is-inversetrue-and-when.html



It's much simpler: If you map the same foreign key column twice, you need to "disable" one side by making it inverse. Which side varies.



If I have a one-to-many with a persistent List or Map, I'd make that side inverse="false" and the many-to-one should be disabled for updating/insertion with insert="false" and update="false".



If I have one-to-many with a persistent Set, I'd make that side inverse="true" and let the many-to-one update/insert the foreign key column.



If I have a many-to-many with a persistent Set on both sides, I can pick which side is "disabled", no difference.



If I have a many-to-many with a persistent List or Map on one of the sides, I need to enable that side and disable the other side (otherwise the index/map key of that list or map isn't stored.)

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now