Submitted by sneha on Sun, 04/15/2018 - 08:09
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. [node:read-more:link]
Submitted by sneha on Sun, 04/15/2018 - 08:09
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. [node:read-more:link]
Submitted by sneha on Sun, 04/15/2018 - 08:08
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. [node:read-more:link]
Submitted by sneha on Sun, 04/15/2018 - 08:07
A composite key is a primary key composed of multiple columns.
When you are creating a composite key, your persistent class must override the equals() and hashCode() method. This is required for for Hibernate caching to work correctly. It must also implement the Serializable interface.
Best way to do this is to create a class with all your composite key fields, mark it as @Embeddable and then annotate a field of that class type with @Id in your entity class.
@Embeddable
public class MyCompositeID implements Serializable {
int field1;
Submitted by sneha on Sun, 04/15/2018 - 08:06
Pages