Hibernate Tutorials

Difference Query.list() Query.iterate() Hibernate

Query.list() vs Query.iterate() Note: Before going into the subject Query.list() Query.iterate(), it is advised to know about Eager and Lazy initializations. Knowledge of queries is very important as they impact the performance else a complex query may take a abnormal long time to execute. Both methods list() and iterate() are…

Difference between Eager Initialization Lazy Initialization

Eager Initialization Lazy Initialization To increase the performance while retrieving records from a database table, Hibernate uses two styles – Eager Initialization and Lazy Initialization. Concept-wise, a good programming practice is lazy initialization; but both have their own importance in coding. Lazy initialization (or instantiation) There are two types of…

Difference bewteen session.get session.load Hibernate

Note: Before going into the subject, it is advised to know about Eager and Lazy initializations. In Hibernate, to get the the information of a specific record, we have two methods get() and load(), both defined in Session interface. Then what is the difference between them and when to use…

Relational Associations Tutorial Hibernate

Hibernate Relational Associations Tutorial Two important features of Hibernate are Inheritance (Hierarchical) Mapping (supported by table-per-subclass etc.) and Relational Associations (supported by one-to-many etc.) The first one is discussed earlier and now let us go for the second one. In database terminology, an association denotes a relationship between two tables.…

Differences between Table per class Table per subclass Table per concreteclass

Table per class vs Table per subclass vs Table per concreteclass To understand better, it is summarized all the differences between three hierarchical models of Hibernate. 1. Table Per Class 2. Table Per Subclass 3. Table Per Concreteclass Introduction notes for the above three models is available at Inheritance (Hierarchical)…

Many-to-Many Example Hibernate

Many-to-Many Hibernate There are two styles to maintain association in many-to-many Hibernate – a) using Set and b) using Map. Many-To-many Relationship: In many-to-many relationship, as the name implies, many records of one table are associated with many records of another table. Concept: One Student may attend multiple courses and…

One-to-One Example Hibernate

One-to-One Example Hibernate One-To-one Relationship: In one-to-one relationship, one record in one table is related to exactly to one record in another table. The two tables are associated with a foreign key. That is, the primary key of one table is the foreign key in another table. Concept: One Student…

Many-to-One Example Hibernate

Many-to-One Hibernate Note: It is advised to read One-to-Many association before going this. You have seen one example on one-to-many involving dept (corresponding Dept class) and employee (corresponding Employee class) tables. You have achieved this in Java by adding many objects of Employee to Dept object through Set. Many-to-one is…

One-to-Many Example Hibernate

One-to-Many Hibernate Earlier in hierarchical relationships, when beans with hierarchical relationship exist, we created tables with different strategies like table-per-subclass etc. Now the other way is we will have tables with foreign key relational associations, let us create bean classes accordingly and insert records to all the tables. The most…

Table Per Concreteclass Example Hibernate

Table-per-concreteclass Hierarchy Note: Before going through this application, it is advised to read Hibernate Mapping Tutorial and also Table per class hierarchy. In this Table Per Concreteclass style, two tables for each subclass are created. The super class variables are placed in each subclass. Observe the screenshots at the end…

Table Per Subclass Example Hibernate

Table Per Subclass Hierarchy Note: Before going through this application, it is advised to read Hibernate Mapping Tutorial and also Table per class hierarchy. In this Table Per Subclass style, three tables are created one for each Java program. Here, foreign key is maintained between the tables. The three tables…

Table Per Class Example Hibernate

Table Per Class Hierarchy Note: Before going through this application, it is advised to read Hibernate Mapping Tutorial. In this Table Per Class style, only one table is created with sufficient columns to accommodate all the properties of each class involved in hierarchy. Because all the records of each class…

Inheritance Hierarchical Mapping Tutorial Hibernate

Inheritance Hierarchical Mapping Java, being an OOPs language, supports inheritance for reusability of classes. Two types of reusability exists – "is-a" and "has-a" relationship. The relational model supported by Hibernate is "has-a" relationship. How Hibernate writes tables for the Java classes involved in inheritance? Hibernate comes with a provision to…

Pagination Example Hibernate

Pagination Hibernate Tutorial If Hibernate fetches large amount of data (records) from the database, it consumes lot of memory. To consume less RAM memory, the data can be obtained in installments from the database. One solution is using pagination . The idea behind Pagination Hibernate is to divide the large…

First level Second level Cache Example Hibernate

Cache Hibernate Tutorial Note: Use the same Student First Program. Just change the client program and modify the XML files and also add a new XML file ehcache.xml. Now go on read Cache Hibernate. We know, file reading with BufferedInputStream gives more performance (around 1500 times more) than FileInputStream. It…

list() iterate() Lazy Eager Initialization Hibernate

list() iterate() Hibernate Before going into the subject, first let us know what is meant by lazy initialization and eager initialization. Concept-wise, a good programming practice is lazy initialization; but both have their own importance in coding. Lazy initialization (or instantiation) There are two types of initializations in a programming…

get(), load(), delete(), Update() Hibernate

get() load() delete() Update() Hibernate Tutorial on Performance issues involved 1. Use the same programs of First Program – Student. Now only client program changes (earlier it was StudentClient.java). 2. Keep ready four records with sid numbers 100, 101, 102 and 103 because we are doing operations on these records.…

Reverse Engineering Hibernate Example

Reverse Engineering Hibernate? Reverse of hbm2ddl is reverse engineering. Lot of confusion. Yes, really. To get clarity, let us know the answers for some more questions. Do you know the following property in hibernate.cfg.xml file?

The above property tag is optional in xml file. The property is if the…

hbm2ddl HibernateSessionFactory Hibernate

hbm2ddl HibernateSessionFactory Second Program on Hibernate – Employee Note: It is advised to though the previous first Program – Student as this is continuation of the previous where new features are added. The new features in this program are: Creating table (by name Employee) in the database using hbm2ddl.auto option…