Proxy Objects,Eager and Lazy Fetch Types

Lazy Initialisation: Lazy Fetch Types: Lazy Initialisation do not initialise the entire object,it first initialise only the first level variables and it initialise the second level such as a list of address only when we actually want to access it. Now in our example suppose we have to fetch the values for…

Continue reading

Hibernate-Value Types and Embedding Objects

Lets first understand what is a Value Type. Suppose in your entity class you have an object as a member variable which has its own attribute but which does not have a meaning unless it has a context with the entity class. For example In our entity class UserDetails suppose…

Continue reading

Hibernate-Primary Keys

Hibernate Primary keys   As we know @Id creates a primary keys in our previous post. First lets understand what is a natural and a Surrogate keys Natural Keys: Suppose in your application you have a column which is mandatory and whose value will be distinct for business reason so…

Continue reading

Retrieving Objects using session.get()

In this post we will retrieve the record that we have inserted in previous post As SessionFactory is one per application and its very expensive we will use the same sessionFactory object which we used to save the record and get a new session from it to retrieve the record.…

Continue reading

Useful Annotation for Model Class

In out previous post we have see how we can change the table name and the Model name using the @Entity (name=”TABLE_NAME“)  and @Column (name=”COLUMN_NAME“)   Here when we use the @Entity (name=”TABLE_NAME“) the entity name  also gets changed,so if we want to change only the table then use @Table(name=”TABLE_NAME”) suppose we…

Continue reading

Hibernate Name Annotation

Suppose we want to have a different table name to that of the model class(Default),then how to do that, @Entity (name=”USER_DETAILS“)  is the annotation used to specify the Table Name and not the default. Similarly we can have different column names also against the default names,see below code, Use @Column (name=”USER_ID”)  for…

Continue reading

Importance of hbm2ddl and show_sql

Importance of hbm2ddl and show_sql Similar posts: Hibernate Setup for Eclipse Writing Model Class and Saving Object Hibernate-Working with Collection-part 1 [@ElementCollection,@JoinTable,@JoinColumn] Hibernate-Working with Collection-part 2 [adding primary key] Proxy Objects,Eager and Lazy Fetch Types

Continue reading

Writing Model Class and Saving Object

Steps required for saving a Model  without hibernate JDBC Database configuration The Model object service method to create teh model object Database design DAO method to save the object using sql queries. When we are using hibernate lot of these are not required and it also becomes very easy so…

Continue reading