Friday 15 May 2015

java - Hibernate - List referencing superclass -


I have a question about succession in Hibernation if I have the following classes:

 < Code> @ Entity @Table (name = "people") @ Inheritance (strategy = inheritance type.joint) @discimintercolumn (name = "discretion", discriminatorType = DiscriminatorType public class student @ Entity @Table (name = "students" ) @DiscriminatorValue ("s") Expands the student of the public class   

Then everything I want to do is to all Normally handles the following categories:

  Public class course {... @ManyToMany & lt; person & gt; students of the private list; ...}   

I would like to be able to deal with the list of students as a list instead of the list of students, so list that a student or teacher can be a student. Anyway I have to do this And yet, do they have a student / teacher Be released as Huon? What's significant to understand the reality Smart 'hibernate? Has this ability to be in hibernation?

Your configuration is fine, hibernate can handle it. Whenever an example of student is in progress, Hibernation will generate two inserted statements, one for the people table and another for the students Will have to. You can do this for example:

  person p = new student (); Session.persist (p);   

Nothing changes when a union occurs, for example:

  course c = new course (); C.students = new arreelist & lt; Person & gt; (); Person p = new student (); S.persist (p); C.people.add (p); Session.persist (c);   

PS : You can change from course.students course.people because this list is Teacher should also be an example.

No comments:

Post a Comment