In this Hibernate CRUD Example, we will learn how to use Hibernate to perform CRUD operations using XML Mapping. We will be using Oracle database and build an Employee Management System which has the capabilities of Creating a new employee, Getting all the employees, Update the existing employee, Delete an employee. … [Read more...]
Difference between session.get() and session.load() in Hibernate
What is the Difference between session.get() and session.load() in Hibernate ? This is one of the most asked interview question in Hibernate. Both the get() and load() methods are defined in the Session interface and used to retrieve the information of a specific record. In this article, we will see what is the difference between then and when to use which method. … [Read more...]
Hibernate Component Mapping using XML
Previously we have learned about Component Mapping in Hibernate using Annotations. In this example, we will learn about Hibernate Component Mapping using XML. In our example, we have two classes Employee and EmployeeAddress. The Employee can have an Address but Address cannot exist separately without Employee. Since the Employee and Address entities are strongly related, it is … [Read more...]
Component Mapping in Hibernate Using Annotations | @Embeddable & @Embedded
In this example, we will learn about Component Mapping in Hibernate Using Annotations. Component Mapping represents the has-a relationship, the composition is stronger association where the contained object has no existence of its own. For example, Employee has an Address, an address cannot exist separately without Employee. Since the Employee and Address entities are strongly … [Read more...]
Hibernate Embeddable Composite Primary Key | @Embeddable, @EmbeddedId
In our previous example, we have seen how to create a Composite key in Hibernate using <composite-id> tag and Annotations. In this Embeddable Composite Primary Key example, we will be declaring the IDs (Primary Key fields) as a separate class annotated with @Embeddable annotation. An Employee is identified by its EmployeeId, which is defined by empId and department. Let's … [Read more...]
Hibernate Composite Primary Key Tutorial – Using composite-id tag & Annotations
If a database table has more than one column as the primary key then we call it as composite primary key. In this Hibernate Composite Primary Key tutorial, we will learn how to define Composite Primary Key using <composite-id> tag and Annotations. … [Read more...]
Hibernate Inheritance – Table Per Concrete Class Hierarchy Example(XML Mapping & Annotation)
Table per Class Hierarchy strategy will be having a single table for both the Parent class and the Sub class separated by a discriminator column. In Table per Subclass Hierarchy, subclass table will be mapped to the Parent class table by primary key and foreign key relationship. In Table Per Concrete Class Hierarchy also individual table will be created for each class. The … [Read more...]
Hibernate Inheritance – Table Per Subclass Hierarchy (XML Mapping & Annotation)
In the previous example we have seen Table per Class Hierarchy strategy, there we will be having a single table for both the Parent class and the Sub class separated by a discriminator column. In this Table per Subclass Hierarchy Example, subclass table will be mapped to the Parent class table by primary key and foreign key relationship. … [Read more...]
Hibernate Inheritance – Table Per Class Hierarchy (XML Mapping & Annotation)
Java being an Object Oriented Language, it supports one of the most powerful concept "Inheritance". Object Oriented Systems generally supports both IS-A and HAS-A relationships, whereas Relational Model supports only HAS-A relationship. Hibernate can help you map such kind of entities into the Relational table based on the strategy selected. Types of Inheritance in … [Read more...]
Hibernate Many To Many Mapping Example – Annotation
In this Hibernate Many To Many Mapping Example, we will learn how Hibernate Many To Many relationship works(Using Annotation). Let's take the Example of Employee and Department, one Employee can be part of many Departments and similarly, one Department can have many Employees. Let's dig into the code. … [Read more...]
Hibernate One To Many Mapping Example Using Annotation
Previously we have learned about Hibernate One To One Mapping Using annotation. In this Hibernate One To Many mapping Example, we will learn about One To Many mapping between Java objects and database tables using Hibernate framework (Annotation Mapping). … [Read more...]
Hibernate One To One Bidirectional Mapping Example – Foreign Key(Annotation)
In this article, we will learn how to achieve Hibernate One To One Bidirectional Mapping using the JPA Annotations with Foreign Key, in the previous One To One Bidirectional Mapping Example we used only the Primary Key. This Annotation approach is just an alternative to the XML mapping which we used in our earlier article Hibernate One To One Mapping XML Example with Foreign … [Read more...]