• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in config. JPA in JBOSS

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I have developed application using JPA,Struts and Tomcat.
it works fine, i changed my application server as JBOSS-4.x.

I am new to JPA, so i am not able config. JPA persistence.xml with JBOSS.
Its not looking the persistance.xml generated by me, it gives ClassCastException.

Please Help.....


:roll:
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the full stack trace for the exception. Also post the persistence.xml file.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar problem.
Here is my persistnece.xml :


I have put the META-INF folder (which contains persistance.xml, manifest.mf and orm.xml files) under src folder.
The source file(s) (e.g. User.java) is(are) located in src/main/java/my/pkg/web/dao.

The error i get, when trying to access my page is (sending the stack trace):


java.lang.NoClassDefFoundError: WEB-INF/classes/my/pkg/web/dao/User(wrong name: my/pkg/web/dao/User)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:621)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
java.net.URLClassLoader.access$000(URLClassLoader.java:56)
java.net.URLClassLoader$1.run(URLClassLoader.java:195)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:188)
org.jboss.mx.loading.RepositoryClassLoader.findClassLocally(RepositoryClassLoader.java:690)
org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:670)
java.lang.ClassLoader.loadClass(ClassLoader.java:307)
org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:200)
org.jboss.mx.loading.UnifiedLoaderRepository3.loadClassFromClassLoader(UnifiedLoaderRepository3.java:312)
org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:189)
org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
java.lang.ClassLoader.loadClass(ClassLoader.java:300)
java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:592)
java.lang.ClassLoader.loadClass(ClassLoader.java:252)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1345)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:247)
org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:135)
org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1009)
org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1081)
org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:871)
org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:758)
org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
srcsi.ezk.web.actions.preview.Preview.getMockUsers(Preview.java:37)
srcsi.ezk.web.actions.preview.Preview.executeAction(Preview.java:30)
srcsi.web.action.GlobalAction.executeCustom(Unknown Source)
srcsi.web.action.CustomAction.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
srcsi.web.filter.DefaultFilter.doFilter(Unknown Source)
srcsi.web.filter.EncodingFilter.doFilter(Unknown Source)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)



Thanks in advance.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what the error message is saying is that it expected to find the User class in a certain directory within the WAR file, but could not.

Are you building a WAR or an EAR? What are the contents of the WAR/EAR? (You can find this out by running the jar utility with the -tf option.)

Are you deploying and running the app in an IDE, such as Eclipse, or are you deploying manually?
 
Rade Treci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply.

I forgot to say that I'm deploying (and running) the application in Eclipse 3.4 (JDK 6 , JBoss 4.2).
The path to User.java in the deployement folder is:

- project.war / WEB-INF / classes / my / pkg / web / dao / User.class

So I really don't know what to do here.

EDIT: Oh yeah, one more thing I pointed (changed the server settings in Eclipse) JBoss to a custom deploy folder so the project.war mentioned above, IS a folder.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Is there any way you could do this manually rather than relying on Eclipse to do the build and deploy? I suspect that it is an Eclipse issue and that doing things manually would yield better results.

2) Also, is this the first such app you have tried? What other Java EE apps have you built and deployed using Eclipse?

3) Are you using JBoss Tools?
 
Rade Treci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Probaly there is but it is required of me to use strictly Eclipse enviroment ...

2) It is first of this kind (JBoss + JPA(Hibernate) combination)

3) Yes.

I was working on this today a few hours and cleaned and imported the libs again etc and now i get another (different) error :
Heres the stack trace:


I think that the problem is maybe that the persistance.xml can't be seen...or maybe I'm missing something else ?

Here is the code of Preview.java class (which actually causes the crash) :


I'm a JPA beginner so I'm on really unstable ground here , so every help is appreciated.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try removing the "class" entry from the persistence.xml file. If your User class is properly annotated, you don't need that entry.

Also, post the contents of your war file (or directory). The WAR directory might be in a subdirectory of workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core (this is where things get tricky - I don't have the exact same version of Eclipse you have. If you were doing things manually I could tell you exactly where to look, but since you insist on working within Eclipse you will have to find where things are located on your machine. I can tell you where things appear for me, but it might not match.)
 
Rade Treci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i remove the "class" entry from the persistence.xml file i get the same exception which I posted yesterday.

The contents of the war directory :
 
Rade Treci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also I forgot to tell you that META-INF folder also exists in the src folder of the Java project in Eclipse.


I copied the META-INF folder to public_html folder (to be included in war) I don't know is it ok
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the contents of orm.xml.
 
Rade Treci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Contents of orm.xml
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vote! We are having exactly the same problem... Any solution since then?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You are packaging the persistence.xml in the .war/META-INF. The spec doesn't allow this. Try packaging the persistence.xml (and orm.xml) in .war/WEB-INF/classes/META-INF or in the META-INF of some jar file under .war/WEB-INF/lib/

By the way, i would have expected the persistence.xml to be ignored when it's in .war/META-INF, instead of throwing this exception

P.S: Your orm.xml doesn't contain anything, so you can even delete it.

 
Rade Treci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
10 min ago I solved it and exactly that was the problem (thanks Jaikiran Pai for pointing this out).

The root of the problem was that I've put the META-INF folder directly under .war/ folder instead under WEB-INF/classes , where it really should go. As soon I realized this and copied under WEB-INF/classes it worked and I didn't got any exceptions.

Thank you, again, all for your help.


P.S: Your orm.xml doesn't contain anything, so you can even delete it.


PS: Deleted it, works fine
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic