Tag Archives | hibernate

Spring + Hibernate + MySql + Maven Example

In this tutorial, I will show you how to integrate Hibernate with Spring 3. Tools and technologies used : Hibernate Spring MySql Maven Eclipse First create a new Dynamic Web Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. Sql Script Use the following Sql Script [...]

Continue Reading ... Comments { 11 }

Hibernate – @MappedSuperclass How to override column identifier

In this tutorial I will show how to override an attribute from mapped super class. 1. Sql Script Use the following Sql Script for creating table. 2. Pojo Now create GenericId and User Class as following.GenericId.java : an abstract class, annotated with @MappedSuperclass that have id column User.java : an @Entity class that extends the [...]

Continue Reading ... Comments { 1 }

Hibernate Self Join Many to Many Mapping with Extra Column using Annotation

In this tutorial I will show you how to implement Self-Join Many to Many mapping with an extra column using Hibernate Annotation. Figure 26.1 illustrates Self Reference many-to-many relationship. Figure 26.1 According to this relationship each person can have friends and each friend is a person. First create a new Java Project and configure it [...]

Continue Reading ... Comments { 0 }

Collection has neither generic type or OneToMany.targetEntity() defined

Exception “org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined:“ I am getting following Exception Solution “Hibernate must know what type of object is in a Set, so add custom parametrized class in Set as shown below.“ private Set employees; //Exceptionprivate Set<Employee> employees; //Works Fine

Continue Reading ... Comments { 1 }

Null value was assigned to a property of primitive type setter of

Exception “org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of“ I am getting following Exception Solution “Use the non-primitive wrapper types (eg Integer instead of int)“

Continue Reading ... Comments { 0 }

Hibernate Interceptor

It is useful for the application to react to certain events that occur inside Hibernate. This allows for the implementation of generic functionality and the extension of Hibernate functionality. Hibernate Interceptor provides an API which one can implement to intercept various operation like save and delete of an entity. The Interceptor interface provides callbacks from [...]

Continue Reading ... Comments { 0 }

Hibernate Native Sql

You can also express queries in the native SQL dialect of your database. This is useful if you want to utilize database-specific features such as query hints or the CONNECT keyword in Oracle. It also provides a clean migration path from a direct SQL/JDBC based application to Hibernate. Hibernate3 allows you to specify handwritten SQL, [...]

Continue Reading ... Comments { 1 }

Hibernate Named Query using Annotation

We don’t like to see HQL string literals scattered all over the Java code unless they’re necessary. Hibernate lets you externalize query strings to the mapping metadata, a technique that is called named queries. This allows you to store all queries related to a particular persistent class (or a set of classes) encapsulated with the [...]

Continue Reading ... Comments { 0 }

Hibernate Named Query (XML Mapping)

We don’t like to see HQL string literals scattered all over the Java code unless they’re necessary. Hibernate lets you externalize query strings to the mapping metadata, a technique that is called named queries. This allows you to store all queries related to a particular persistent class (or a set of classes) encapsulated with the [...]

Continue Reading ... Comments { 0 }

Hibernate – Difference between session’s get() and load()

Session.Load() 1. If load() can’t find the object in the cache or database, an exception is thrown. The load() method never returns null. If no row is found, it throws ObjectNotFoundException 2. The load() method may return a proxy instead of a real persistent instance, allowing lazy initialization and thus better performance . A proxy [...]

Continue Reading ... Comments { 0 }