Hibernate one to many array list

Posted on 2009-02-24
Last Modified: 2012-05-06
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

Question by:JianJunShen
    LVL 20

    Assisted Solution

    by:chaitu chaitu
    LVL 20

    Assisted Solution

    by:chaitu chaitu
    LVL 10

    Assisted Solution


    Accepted Solution

    I also found following comments in the link mentioned below:

    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.)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    Suggested Solutions

    Title # Comments Views Activity
    Return ZipOutputStream using Servlet 2 27
    changePi Challenge 15 56
    nestparen challenge 4 34
    json format text only 4 48
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now