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.
Submitted by sneha on Thu, 11/14/2013 - 03:45
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 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 Mon, 08/12/2013 - 12:03
Hibernate 4 jars can be downloaded from the SourceForge web site at http://sourceforge.net/projects/hibernate/files/hibernate4. If this url doesn’t work or get changed, just search ‘hibernate 4 jars download sourceforge’ in Google. The distribution version downloaded here is 4.2.4. Except for the version numbers, the jar names and folder structure should be same across any version of hibernate4 distribution.
Submitted by sneha on Mon, 10/12/2015 - 02:35
Submitted by sneha on Sat, 10/17/2015 - 19:25
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 Mon, 10/19/2015 - 04:31
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.
We can use @AttributeOverride annotation to override the details of a field of the embedded class and then enclose all such @AttributeOverride annotations inside @AttributeOverrides annotation.
Submitted by sneha on Wed, 10/21/2015 - 10:34
When you load an embeding class, it may load its embedded collections either lazily or eagerly.
Important points about eager and lazy fetch types in Hibernate
By default, when you load an embedding class (E.g. User or Company) using session.get,
Submitted by sneha on Wed, 10/21/2015 - 22:38
When referencing entities from other entities, we are mapping two entities whereas when referencing a value type we are embedding (or containing) a value type within an entity.
When mapping two entities, we annotate both classes as @Entity, and the mapping type is specified using the annotations @OneToOne, @OneToMany, @ManyToOne or @ManyToMany, over the reference variable declaration of an entity in another entity.
We will consider two entities for mapping examples – a student class and a course class.
Submitted by sneha on Sat, 10/24/2015 - 22:12
In the SINGLE_TABLE strategy, hibernate will create a single table for all the classes in an inheritance hierarchy. There will be a discriminator column that tells us the class to which that row belongs.
In this example, we will create and save three entity classes – Shape, Rectangle and Circle; where Rectangle and Circle extends from Shape.