Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sanjeev Kumar
java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be
February 26, 2013 10:19 PM
Answer

Sanjeev Kumar

Rank: New Member

Posts: 5

Join Date: February 26, 2013

Recent Posts

Hi everyone,
I am using Liferay CE 6.1, tomcat 7.
I am developing custom portlets in my liferay project.
I am connecting to external database MySQL.
I need to add hibernate3.jar to implement my custom API's in my portlet.
I tried adding the hibernate3.jar explicitly in my WEB-INF/lib folder and also tried adding through liferay-plugin-package.properties to include the dependency jar which liferay uses.
But I get the same error, saying org.hibernate.HibernateException: Could not instantiate dialect class

BeanLocator not set for servlet context,

java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect.

org.hibernate.HibernateException: Could not instantiate dialect class.

Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayHibernateSessionFactory' defined in ServletContext resource [/WEB-INF/classes/META-INF/hibernate-spring.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Could not instantiate dialect class.

I am not able to go forward until I get rid of this problem, please I need help, thanks in advance...
MICHAIL MOUDATSOS
RE: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot
March 1, 2013 5:58 AM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 107

Join Date: October 4, 2011

Recent Posts

I think ou should first mention what kind of frameworks you use, i.e. "Do you use plain Hibernate?", "Are you using Spring?". This will help people understand your situation better. E.g., for the plain hibernate case, I have tried that in the past and there was no problem. I just had to add hibernate and all of its dependencies to my lib folder (and of course initialize it properly emoticon).
David H Nebinger
RE: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot
March 1, 2013 6:24 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 4496

Join Date: September 1, 2006

Recent Posts

You're encountering class loader issues...

Basically you've got your own hibernate jar loaded in your class loader, but the liferayHibernateSessionFactory instance is defined in Liferay's class loader. In Liferay's class loader, it has already created the connection and established the dialect to use, in this case a MySQLDialect.

So you're trying to reuse the connection from their class loader in your own class loader and, of course, although both have a Dialect interface defined, they are completely different class and cannot be cast around.
Sanjeev Kumar
RE: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot
March 6, 2013 8:51 PM
Answer

Sanjeev Kumar

Rank: New Member

Posts: 5

Join Date: February 26, 2013

Recent Posts

But the error occurs when the hibernate jar is added in lib folder, not while implementing the API's which are built on hibernate.
MICHAIL MOUDATSOS
RE: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot
March 6, 2013 9:03 PM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 107

Join Date: October 4, 2011

Recent Posts

Sanjeev Kumar:
But the error occurs when the hibernate jar is added in lib folder, not while implementing the API's which are built on hibernate.
So, you mean you haven't written a single line of code, not even a configuration file, anything?
Sanjeev Kumar
RE: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot
March 7, 2013 2:28 AM
Answer

Sanjeev Kumar

Rank: New Member

Posts: 5

Join Date: February 26, 2013

Recent Posts

we are connecting to different (application) Database using hibernate.
We created API to connect to the other application database. The API is using hibernate to connect the other application.