30 Oct

Bidirectional Many-To-Many Relationship with Join Tables in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In many to many relationship, one multiple objects can have relationship with multiple target objects. Let’s consider CD and Artist. So multiple CDs can be written by multiple Artists or multiple Artists can write multiple CDs. So we will create three tables CD, CDArtist and Artist in the database and we will see how many-to-many relationship works step by step. Read More

28 Oct

Bidirectional One-To-One Relationship with Join Tables in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to one relationship, one source object can have relationship with only one target object. Let’s consider CD and Artist. So one CD can be written by one Artist or an Artist can write only one CD. So we will create two tables CD and Artist in the database and we will see how one-to-one relationship works step by step.

Now we will apply one-to-one relationship. So only one CD can be written by only one Artist.

A bidirectional one-to-one association on a join table is possible, but extremely unusual. Read More

26 Oct

Bidirectional One-To-Many/Many-To-One Relationship using Join Tables in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to many or many to one relationship, one source object can have relationship with multiple target objects or multiple target objects will have relationship with only one source object. Let’s consider CD and Artist. So one CD can be written by multiple Artists or multiple Artists can write only one CD. So we will create three tables CD, Artist and CDArtist in the database and we will see how one-to-many/many-to-one relationship works step by step.

The following is an example of a bidirectional one-to-many association on a join table. The inverse=”true” can go on either end of the association, on the collection, or on the join. Read More

10 Oct

Bidirectional One-To-One Relationship on Primary Key in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to one relationship, one source object can have relationship with only one target object. Let’s consider CD and Artist. So one CD can be written by one Artist or an Artist can write only one CD. So we will create two tables CD and Artist in the database and we will see how one-to-one relationship works step by step.

Now we will apply one-to-one relationship. So only one CD can be written by only one Artist.

In One-To-One relationship on primary key CD table and Artist table have cdId as primary keys, where primary key cdId in Artist table is a reference to CD table.

Read More

08 Oct

Bidirectional One-To-One Relationship on Foreign Key in Hibernate

In bidirectional association, we will have navigation in both directions, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to one relationship, one source object can have relationship with only one target object. Let’s consider CD and Artist. So one CD can be written by one Artist or an Artist can write only one CD. So we will create two tables CD and Artist in the database and we will see how one-to-one relationship works step by step.

Now we will apply one-to-one relationship. So only one CD can be written by only one Artist.

In One-To-One relationship on foreign key, CD table has an artistId as foreign key with unique constraint, which is a reference to Artist table. Read More

17 Sep

Bidirectional Many-To-One/One-To-Many Relationship in Hibernate

In bidirectional association, we will have navigations in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In many-to-one/one-to-many relationship, multiple source objects can have relationship with same target object or same target object will have multiple source objects and from both direction the navigation is possible. Let’s consider CD and Artist. So multiple CDs can be written by same Artist or same Artist can have multiple CDs. So we will create two tables CD and Artist in the database and we will see how many-to-one/one-to-many relationship work step by step.

Now we will apply many-to-one/one-to-many relationship. So multiple CDs can be written by same Artist or the same Artist can have multiple CDs. Read More

Share