Advertisement



< Prev
Next >



Hibernate with Collection



An Entity object is an object of our plain old java class(POJO) Model/Business class, which needs to be persisted in a database using Hibernate.

An Entity object may contain a collection object, which contains a collection of objects of another class. This collection object is stored in a separate table, while the Entity object is stored in a separate table in the database.

So, let us understand how to persist a collection object within the database using Hibernate.




Why do we have to add a collection object in an Entity class.


Let's suppose we have two classes User_Details and Contact_Info, where -
Each user may have a couple of important email addresses or phone numbers. Hence, each user object of User_Details, could be associated with the multiple objects of Contact_Info. That's why we are going to need a collection object in User_Details, representing each user with multiple contact info's.

Let's put this example to work and make it easier for you to understand.




Note :







Creating a POJO/Entity class


Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement