Submitted by sneha on Sat, 10/24/2015 - 22:12
In the SINGLE_TABLE strategy, hibernate will create a single table for all the classes in an inheritance hierarchy. There will be a discriminator column that tells us the class to which that row belongs.
In this example, we will create and save three entity classes – Shape, Rectangle and Circle; where Rectangle and Circle extends from Shape.
Submitted by sneha on Wed, 10/21/2015 - 22:38
When referencing entities from other entities, we are mapping two entities whereas when referencing a value type we are embedding (or containing) a value type within an entity.
When mapping two entities, we annotate both classes as @Entity, and the mapping type is specified using the annotations @OneToOne, @OneToMany, @ManyToOne or @ManyToMany, over the reference variable declaration of an entity in another entity.
We will consider two entities for mapping examples – a student class and a course class.
Submitted by sneha on Wed, 10/21/2015 - 22:18
In Many-To-Many mapping, we refer to a collection/list of the entity from another entity and vice versa; and used @ManyToOne annotation on declarations of both entity collections.
We will assume that each course can have many students (many to many), and each student can do many course(many to many).
We will create two entity classes, Course and Student and do a many to many mapping from course to student, and again many to many mapping from student to course.
Submitted by sneha on Wed, 10/21/2015 - 17:50
In One-To-Many mapping, we refer to a collection/list of the entity from another entity and mark the reference variable as @OneToMany. The opposite of this relation from the second entity to the first will be Many-To-One and is annotated as @ManyToOne.
We will assume that each course can have many students(one to many), but each student can do only one course(many to one).
We will create two entity classes, Course and Student and do a one to one mapping from course to student, and many to one from student to course.
Submitted by sneha on Wed, 10/21/2015 - 17:37
In One-To-One mapping, we refer to one entity from another and mark the reference variable as @OneToOne.
In this example, we will consider two entity classes – student class and course class; and do a one to one mapping from course to student.
We will assume that there is a one-to-one mapping between a Course and Student – each course can be taken by only one student.