Fetching strategies in Hibernate

Hibernate uses a fetching strategy to retrieve associated objects if the application needs to navigate the association. Fetch strategies can be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query. Hibernate3 defines the following fetching strategies: Join fetching: Hibernate retrieves the associated instance or…

Continue reading

Joins In Hibernate

Hibernate supports 4 types of joins.. Left Join Right  Join Full Join Inner Join the DEFAULT join in hibernate is Inner join Similar posts: Hibernate Architecture Hibernate Using Mapping File Inheritance Mapping In Hibernate Inheritance-Table Per Class Hierarchy Hibernate-generator-element

Continue reading

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