Submitted by sneha on Wed, 11/13/2013 - 03:12
Consider a user class with an embedded list of addresses, or a company class with a list of employee details. By default, when you load the embedding class (user or company) using session.get, the embedded collection (addresses or employee details) is not actually retrieved from database, but only the top level fields are retrieved. The collection list is retrieved when you call the getter for that embedded collection. This is called lazy initialization fetch in hibernate. The alternative is called eager initialization fetch.
Submitted by sneha on Wed, 11/13/2013 - 01:00
There might be situations where you would want to modify the attributes of the embedded class (eg. Address) within an embedding class (eg. User), for instance, changing the database column name for a field. You can do this within the embedded class itself. But what if you don’t have access to the embedded class or if you want different behavior for two different instances of the embedded class; you will have to override the embedded class behavior in the embedding class.
Submitted by sneha on Wed, 11/13/2013 - 00:02
An entity class can refer to other entity classes or embed value types. An entity is a type on its own and has an existence of its own like a Course and its students. A value type is a type which doesn't have existence of its own, but belongs to an entity like an user and his address. Value types are always completely owned by their containing entity. Once you delete the entity, its associated value types are also deleted. But when you delete an entity, referenced entities still exist: when you delete a Course entity, you don't delete all its students.
Submitted by heartin on Wed, 09/11/2013 - 11:27
Here we will discuss most commonly used basic annotations in hibernate - @Entity, @Table, @Id, @GeneratedValue, @Basic, @Transient, @Temporal and @Lob.
@Entity annotation (javax.persistence.Entity) over the class tell hibernate to treat this class as our entity class that needs to be saved.
Submitted by heartin on Wed, 09/11/2013 - 11:09
Here we will see all the CRUD operations, and also object states and transitions in hibernate. CRUD operations are Create(save), Read(select), Update(update) and Delete(delete). We will see object states in hibernate such a new/transient, attached/persistent and detached.
Submitted by heartin on Wed, 09/11/2013 - 10:31
We will write a simple hibernate application to get started with hibernate.
Before starting, you should:
Submitted by heartin on Thu, 08/29/2013 - 08:06
Hibernate provide Criteria Queries as an object-oriented alternative to HQL. Criteria Query is used to modify the objects and provide restriction for the objects. Many complex queries in HQL or even SQL may become larger over a period of time and spread over many lines; and will be difficult to update and maintain. We have already seen HQL in www.javajee.com/introduction-to-hibernate-query-language-hql.
Submitted by heartin on Wed, 08/28/2013 - 10:09
We can have queries saved with a name and later we can retrieve them simply using that name. We use @NamedQuery annotation to declare a named query. We can also have a named query for native sql. For native SQL we use the annotation @NamedNativeQuery annotation. This is one of the important advantages of having a named query: you can write native SQL. You can retrieve a Query object from a saved query name (hql and native named query) using session.getNamedQuery method.
Submitted by heartin on Wed, 08/28/2013 - 09:02
Parameter binding is the process of binding a Java variable with an HQL statement. Using Parameter binding and not string concatenation for HQL statement creation will also guard against attacks like SQL injection.
Submitted by heartin on Tue, 08/27/2013 - 11:53
Hibernate provides a query language called Hibernate Query Language (HQL). HQL is similar to SQL in syntax, but HQL queries are written against Hibernate's entity objects, not database tables. Hibernate also provide Criteria Queries as an object-oriented alternative to HQL. Criteria Query is used to modify the objects and provide the restriction for the objects. Here we will see the basics of HQL and later in another tutorial we will see criteria queries.