-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Problem creating EntityManagerFactory.
PostPosted: Mon Oct 03, 2005 8:50 am 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
Hi everyone,

I'm doing exactly the way EntiyManager Docummentaion recommends to create an EntityManagerFactory:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager");

But I receive the exception:

java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence

Does anyone know what's wrong?

Thanks, Guilherme


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 2:19 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
HibernatePeristence cla is in hibernate-entitymanager.jar - you havto include this jar in classpath


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 3:11 pm 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
Yes, it is in my classpath!
If you unzip hibernate-entitymanager.jar, you'll see that it isn't any EntityManagerFactory, EntityManager and Persistence class. They're in ejb3-persistence.jar.
These are the jars in my classpath:
ejb3-persistence.jar;
hibernate3.jar;
hibernate-entitymanager.jar;
hibernate-annotations.jar.

Do I have to include other jar? Or do I have to exclude any of these?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 3:19 pm 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
when I use HibernatePersistence, that comes in hibernate-entitymanager.jar:

HibernatePersistence persistence = new HibernatePersistence();
EntityManagerFactory hemf = persistence.createEntityManagerFactory("sistemabancario", new HashMap());
EntityManager em = hemf.createEntityManager();

I get the exception

javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not instantiate dialect class

I think it's not a Driver problem. I've already tested this driver before and didn't get any error.

My persistence.xml is:
<entity-manager>
<name>sistemabancario</name>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>sistemaBancario.servidor.persistencia.vo.BancarioVo</class>
<class>sistemaBancario.servidor.persistencia.vo.PessoaFisicaVo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.gjt.mm.mysql.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/sistemabancario"/>

<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</entity-manager>

Any idea??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 3:40 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Quote:
org.hibernate.HibernateException: Could not instantiate dialect class


this mean that driver's jar isn't in path or is incorrect


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 3:47 pm 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
But it is my path:

mysql-connector-java-3.0.8-stable-bin.jar

and I've tested it in a JDBC connection and it worked.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 4:35 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
what is your tool - command line, ant , eclipse ?

check classpath double - hibernate do same thing like jdbc and instatiate driver same
If you use eclipse (special eclipse rcp) it is another problem - search forum for buddy classloader


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 4:54 pm 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
I am using jboss eclipse ide version 3.1.0.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 5:07 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
try search buddy classloader in this forum and JarVisitor - I think that there are problems with eclipse and jar reading - I haven't tried last hibernate with rcp (or eclipse ide, hibernate tools yet , but I will soon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 7:21 am 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
Ok,thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 8:37 am 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
shouldn't I have a hibernate-service.xml in JBoss in order to configure my dialect class? I do not have it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 8:57 am 
Beginner
Beginner

Joined: Wed Apr 27, 2005 8:27 am
Posts: 27
One thing I do not understand is why JBoss shows these messages:

09:50:34,019 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.8.0
09:50:34,081 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, version: 1.8.0

in console when I execute the line code:

EntityManagerFactory hemf = persistence.createEntityManagerFactory("sistemabancario", new HashMap());

But I am not trying to access HSQL. I am trying to access MySQL. Do you know where in JBoss I have to configure this RDBMS to MySQL, if it is necessary?

Thanks, Guilherme


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.