-->
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.  [ 7 posts ] 
Author Message
 Post subject: Issues Hibernate3 Persistence with EJB3
PostPosted: Tue Apr 01, 2008 2:57 pm 
Newbie

Joined: Fri Mar 21, 2008 12:32 pm
Posts: 9
Hello,

I am trying to use Hibernate3 with EJB3, but I constantly get java.lang.NoClassDefFoundError: javax/persistence/Persistence error in a session EJB where I am calling the hibernate API.

The persistence.xml is as follows which is in the META-INF folder of the EJB:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="mycontext" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>hib.Contact</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/hibernatetutorial"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.connection.pool_size" value="10"/>
<property name="show_sql" value="true"/>
<property name="dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>

The Hibernate API I am using are:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mycontext", new HashMap());
EntityManager em = emf.createEntityManager();
em.persist(contactInserting);

I have all the required jars as shown below and also some extra ones...
ant-1.6.5.jar
ant-antlr-1.6.5.jar
ant-junit-1.6.5.jar
ant-launcher-1.6.5.jar
ant-swing-1.6.5.jar
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
checkstyle-all.jar
cleanimports.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
concurrent-1.3.2.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
ejb3-persistence.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate3.jar
jaas.jar
jacc-1_0-fr.jar
javassist.jar
jaxen-1.1-beta-7.jar
jboss-cache.jar
jboss-common.jar
jboss-jmx.jar
jboss-system.jar
jgroups-2.2.8.jar
jta.jar
junit-3.8.1.jar
log4j-1.2.11.jar
mysql-connector-java-5.0.6-bin.jar
oscache-2.1.jar
proxool-0.8.3.jar
swarmcache-1.0rc2.jar
syndiag2.jar
versioncheck.jar
xerces-2.6.2.jar
xml-apis.jar

All libraries are in the class path.

Any thoughts or ideas if anyone else had similar problem.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 4:41 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
That class is in ejb3-persistence.jar so you either have not got that on your classpath or you've got some classloading issues which we can't diagnose here unless we know how you're deploying Hibernate EntityManager.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 7:16 pm 
Newbie

Joined: Fri Mar 21, 2008 12:32 pm
Posts: 9
Thank you for the respone! However, the way I bring in the libraries is as follows:

I have them all in the EAR module, and refer to them in the EJB. All other libraries are bring picked up, just this one is creating the problem...

If you need more information, I will be happy to provide it to you- this bug is very strange bug...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 8:11 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
What appserver is this? Why are you shipping JPA stuff with your EAR? That's the job of the container, in most cases. Any EE5 container will deploy your entities and whatnot with nothing but META-INF/persistence.xml and a few annotated Entities.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 1:36 pm 
Newbie

Joined: Fri Mar 21, 2008 12:32 pm
Posts: 9
Thanks for your response!

I am using WLS 10.0, JDK 1.5, Hibernate 3.2. I am writing the code using Weblogic Workshop 10.0.

I make sure that when I right click on the EJB project, the libraries are in the build path.

I added all jars because it was constantly failing. I also tried it after removing the unwanted jars but still the result stays the same.

Any other information needed, please let me know and I will be happy to provide it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 1:41 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
You should not need to bootstrap EntityManagerFactory using an EJB3 container -- in other words you should not need to call Persistence.createEntityManagerFactory(). You should only have to specify Hibernate as your provider and ensure that the Hibernate libs are available to be used by WLS. See this thread for a little discussion:

http://forums.bea.com/thread.jspa?threadID=400003226

I have not tested the above but the general idea is that the EJB3 container is responsible for managing the JPA service for you and then you simply inject it to your EJBs or look it up in JNDI.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 2:07 pm 
Newbie

Joined: Fri Mar 21, 2008 12:32 pm
Posts: 9
Thanks for the reply! I tried the following and see that its a problem with the workshop. When I export the application as an ear file (after selecting the jar files to be exported), still, I dont see the jar files being exported. The ear file contains only the Java classes. Since this is what workshop is also doing internally, the application complains ClassNotFound.

Will probably need to either look into the workshop details or manually add the jars and change the MANIFEST-MF to get it to work.

But that is what the problem was!

Thanks for your time and I appreciate your patience!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.