Embedded HSQL Database with Spring

This tutorial will show you how you can work with embedded HSQLDB with Spring framework. This application will show you a CRUD(Create, Read, Update and Delete) operations on the fly using embedded HSQLDB.

Sometimes we need to work with an in memory database when we want to demonstrate certain database centric features of an application during development phase. Such situation may be when there is no access to real database server and we want to perform test on an application on the fly using database operations then this may be very helpful. Spring supports many databases such as HSQL, H2, and Derby as default embedded databases but, we can also use an extensible third party API to plug in new embedded database and DataSource implementations.

Spring supports XML as well as Programmatic configuration of beans but, here we will use XML based metadata configuration.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse. Continue reading “Embedded HSQL Database with Spring”

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. Continue reading “Bidirectional Many-To-Many Relationship with Join Tables in Hibernate”

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. Continue reading “Bidirectional One-To-One Relationship with Join Tables in Hibernate”

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. Continue reading “Bidirectional One-To-Many/Many-To-One Relationship using Join Tables in Hibernate”

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

In unidirectional association, we will have navigation only in one direction, i.e, only one side of the association will have the reference to the other side. The one 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, multiple target objects can have relationship with multiple source objects. Let’s consider CD and Artist. So only one Artist can write multiple CD or a CD can be written by multiple Artists. So we will create three tables CD, Artist and CDArtist in the database and we will see how many-to-many relationship works step by step. Continue reading “Unidirectional Many-To-Many Relationship with Join Tables in Hibernate”

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

In unidirectional association, we will have navigation only in one direction, i.e, only one side of the association will have the reference to the other side. The one 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, single target object can have relationship with only one source object. Let’s consider CD and Artist. So only one Artist 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-one relationship works step by step.

A unidirectional one-to-one association on a join table is possible, but extremely unusual. Continue reading “Unidirectional One-To-One Relationship with Join Tables in Hibernate”

Unidirectional Many-To-One Relationship with Join Tables in Hibernate

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

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

A unidirectional many-to-one association on a join table is common when the association is optional. Continue reading “Unidirectional Many-To-One Relationship with Join Tables in Hibernate”

Unidirectional One-To-Many Relationship with Join Tables in Hibernate

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

In one to many relationship, multiple target objects can have relationship with same source object. Let’s consider CD and Artist. So many 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 relationship works step by step.

A unidirectional one-to-many association on a join table is to specify unique=”true” which changes the multiplicity from many-to-many to one-to-many. Continue reading “Unidirectional One-To-Many Relationship with Join Tables in Hibernate”

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.

Continue reading “Bidirectional One-To-One Relationship on Primary Key in Hibernate”