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 used to retrieve multiple records …

Difference Query.list() Query.iterate() Hibernate Read More »

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 initializations in a programming language …

Difference between Eager Initialization Lazy Initialization Read More »

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 which one. This tutorial throws …

Difference bewteen session.get session.load Hibernate Read More »

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. This tutorial explains the way …

Relational Associations Tutorial Hibernate Read More »

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) Mapping Tutorial Table-per-class Table-per-subclass Table-per-concreteclass …

Differences between Table per class Table per subclass Table per concreteclass Read More »

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 similarly one course may be …

Many-to-Many Example Hibernate Read More »

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 also the same but viewing …

Many-to-One Example Hibernate Read More »

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 unidirectional relational associations are 1. …

One-to-Many Example Hibernate Read More »

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 of the notes. The three …

Table Per Concreteclass Example Hibernate Read More »

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 ETABLE (for Employee), PETABLE (for …

Table Per Subclass Example Hibernate Read More »

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 are available in a single …

Table Per Class Example Hibernate Read More »

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 create tables and populate them …

Inheritance Hierarchical Mapping Tutorial Hibernate Read More »

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 is due to buffering effect. …

First level Second level Cache Example Hibernate Read More »

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 language – eager initialization and …

list() iterate() Lazy Eager Initialization Hibernate Read More »

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. 3. Database school table before …

get(), load(), delete(), Update() Hibernate Read More »

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? update The above property tag is optional in xml file. The property is if the table is not available in …

Reverse Engineering Hibernate Example Read More »

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 (in the first program, we …

hbm2ddl HibernateSessionFactory Hibernate Read More »