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.
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.
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
We will see a simple example to illustrate the LAZY and EAGER Fetch in Hibernate.
Submitted by sneha on Sun, 04/15/2018 - 08:05
When you load an embeding class, it may load its embedded collections either lazily or eagerly.
Important points about eager and lazy fetch types in Hibernate
-
By default, when you load an embedding class (E.g. User or Company) using session.get,
-
The embedded collection is actually retrieved when you call the getter for that embedded collection.
Pages