org.hibernate.MappingException: No Dialect mapping for JDBC type

You might have seen similar kind of exception occurred during performing native queries without entity class and this kind of issue may have been occurred in different databases such as MySQL, Oracle, SQL Server, PostgreSQL etc. Depending upon the database vendor you will get error for JDBC types -4, -9, 7 or 2003 etc. It means that Hibernate is unable to implement a type mapping for database type(for example, table column type float) to java type (float) though float type is listed in the JDBC reference.

Here I will create an example how to query Oracle database without entity class using Hibernate JPA and in what situation it throws the exception “org.hibernate.MappingException: No Dialect mapping for JDBC type: -9”. In this example I will also show you how to resolve the issue.

I assume that you are using Hibernate JPA with Spring Boot application.

Continue reading “org.hibernate.MappingException: No Dialect mapping for JDBC type”

JSF 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate JSF 2, Spring 4, Hibernate 4 and Maven. In the previous example Spring 3, JSF 2 and Hibernate 3 integration example , I have shown how to integrate JSF 2, Spring 3 and Hibernate 3 but I have not used maven there.

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse.

Prerequisites

The following configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven installed and configured
JSF 2, Spring 4, Hibernate 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Continue reading “JSF 2, Spring 4, Hibernate 4 and Maven Integration”

Struts 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate Struts 2, Spring 4, Hibernate 4 and Maven. In the previous example Integrate Spring 3, Struts 2 and Hibernate 3 , I have shown how to integrate Struts 2, Spring 3 and Hibernate 3 but I have not used maven there.

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse.

Prerequisites

The following configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven installed and configured
Struts 2, Spring 4, Hibernate 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Continue reading “Struts 2, Spring 4, Hibernate 4 and Maven Integration”

evict() method in Hibernate

The method evict() removes a single object from Session cache. So before you call evict() the object should be there in the Session cache. Therefore if you save the object first time, you have to save the object via Session.save(object). Subsequent update calls should follow through session.saveOrUpdate(object) or session.update(object) before calling evict() to remove the loaded object from the cache.

From http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-sessioncache

Whenever you pass an object to save(), update() or saveOrUpdate(), and whenever you retrieve an object using load(), get(), list(), iterate() or scroll(), that object is added to the internal cache of the Session.

When flush() is subsequently called, the state of that object will be synchronized with the database. If you do not want this synchronization to occur, or if you are processing a huge number of objects and need to manage memory efficiently, the evict() method can be used to remove the object and its collections from the first-level cache.

Continue reading “evict() method in Hibernate”

Bidirectional Many-To-Many Relationship with Join Tables in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In many to many relationship, one multiple objects can have relationship with multiple target objects. Let’s consider CD and Artist. So multiple CDs can be written by multiple Artists or multiple Artists can write multiple CDs. So we will create three tables CD, CDArtist and Artist in the database and we will see how many-to-many relationship works step by step. Continue reading “Bidirectional Many-To-Many Relationship with Join Tables in Hibernate”

Bidirectional One-To-One Relationship with Join Tables in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to one relationship, one source object can have relationship with only one target object. Let’s consider CD and Artist. So one CD can be written by one Artist or an Artist can write only one CD. So we will create two tables CD and Artist in the database and we will see how one-to-one relationship works step by step.

Now we will apply one-to-one relationship. So only one CD can be written by only one Artist.

A bidirectional one-to-one association on a join table is possible, but extremely unusual. Continue reading “Bidirectional One-To-One Relationship with Join Tables in Hibernate”

Bidirectional One-To-Many/Many-To-One Relationship using Join Tables in Hibernate

In bidirectional association, we will have navigation in both direction, i.e, both side of the association will have the reference to the other side. The both side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to many or many to one relationship, one source object can have relationship with multiple target objects or multiple target objects will have relationship with only one source object. Let’s consider CD and Artist. So one CD can be written by multiple Artists or multiple Artists can write only one CD. So we will create three tables CD, Artist and CDArtist in the database and we will see how one-to-many/many-to-one relationship works step by step.

The following is an example of a bidirectional one-to-many association on a join table. The inverse=”true” can go on either end of the association, on the collection, or on the join. Continue reading “Bidirectional One-To-Many/Many-To-One Relationship using Join Tables in Hibernate”

Unidirectional Many-To-Many Relationship with Join Tables in Hibernate

In unidirectional association, we will have navigation only in one direction, i.e, only one side of the association will have the reference to the other side. The one side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In many to many relationship, multiple target objects can have relationship with multiple source objects. Let’s consider CD and Artist. So only one Artist can write multiple CD or a CD can be written by multiple Artists. So we will create three tables CD, Artist and CDArtist in the database and we will see how many-to-many relationship works step by step. Continue reading “Unidirectional Many-To-Many Relationship with Join Tables in Hibernate”

Unidirectional One-To-One Relationship with Join Tables in Hibernate

In unidirectional association, we will have navigation only in one direction, i.e, only one side of the association will have the reference to the other side. The one side of the association will implement one of the collection interfaces, if it has the reference to the other entity.

In one to one relationship, single target object can have relationship with only one source object. Let’s consider CD and Artist. So only one Artist can write only one CD. So we will create three tables CD, Artist and CDArtist in the database and we will see how one-to-one relationship works step by step.

A unidirectional one-to-one association on a join table is possible, but extremely unusual. Continue reading “Unidirectional One-To-One Relationship with Join Tables in Hibernate”