• 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 persistence.xml: org.hibernate.ejb.HibernatePersistence cannot be cast

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

I'm using JBoss 4.2.2 and building an application with Hibernate 4.0.1.Final. I'm confused about how to setup my persistence.xml provider class. Currently, in my JAR's META-INF directory, I have this persistence.xml



but upon deploying my JAR to JBoss, I'm greeted with this error



What class should I be using for the provider given my app server and Hibernate version? - Dave
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jboss includes its own implementation of JPA they are probably being loaded by separate class loaders.

This link may have some insight (try the last suggestion for configuring the classloaders)
http://stackoverflow.com/questions/3759144/org-hibernate-ejb-hibernatepersistence-cannot-be-cast-to-javax-persistence-spi-p

You could try excluding JPA and using the ones that JBOSS has but with an old version like this I imagine there will be other issues, and you would be using JPA 1.0



Good luck
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JBoss 4.x and Hibernate 4.x do NOT work well together. You may get it to work but some core
components of JBoss use it's internal hibernate.

We are stuck with Spring 2.5.6 for this very reason.

WP
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you talking about the suggestion from Pascal Thivent or Stephan?

Btw, I tried removing the dependencies related to JPA 2.0 but got another exception ...

 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah I figured that would happen

I was talking about Stephan. You can look also at this post it is along the same lines

http://stackoverflow.com/questions/8476944/class-loading-isolation-issue-or-how-to-use-jpa2-on-jboss-5-x

The idea is to try to get jboss to use the classes packaged in your WAR and not the versions it has.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that clarification. I'm going to check that out, but my application is a JAR, not a WAR. I've got through hell trying to figure out how to instruct JBoss to prefer the classes in my JAR instead of its own, but I haven't figured out how. If you know, or have suggestions for another packaging structure, I'm grateful.

- Dave
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not a web-app? What exactly do you mean by deploying a jar?
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill

An EJB jar is an example of a deployable artifact, it doesn't have to be an EAR or WAR.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only thing in the JAR is a Quartz job that I want to run periodically (There are some JBoss annotations that let me set up the cron). Everything else in the JAR are classes that support that job. Our sysadmin has said I need to do this in JBoss instead of setting up a traditional Unix cron job.

I'm open to other packaging configs, but I don't think WAR is appropriate because I don't have any web components.

Thanks for getting back to me with all the Olympics on, - Dave
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:Bill

An EJB jar is an example of a deployable artifact, it doesn't have to be an EAR or WAR.



Thanks James I had read a little on it awhile back (although I have zero experience with it) however I though that was something that came with the EJB 3 stuff and was newer than JBOSS 4. Anyways I stand corrected


Edit I found this with all the deployment descriptors for a newer version of JBOSS I did not see an equivalent document for 4.

https://docs.jboss.org/author/display/AS71/Deployment+Descriptors+used+In+AS7.1
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't actually have any EJBs so should I still be building an EJB jar? - Dave
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Alvarado wrote:I don't actually have any EJBs so should I still be building an EJB jar? - Dave



Well it has to use some kind of deployment descriptor. Can you look at that link on my last post and tell me which one you are using to deploy your jar?
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After reading over your link with the deployment descriptors, I'm at a loss. What deployment descriptor is appropriate for my application, in which I just want to run a Quartz job periodically? I appreciate any recommendations although I'm going to see if jboss-client.xml is supported for JBoss 4. - Dave
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well whatever deployment descriptor you have seems to be working for you as far as deployment is concerned. I was hoping that you could use jboss-classloading.xml to force your application to use the libs that are included with your application but it seems this was added in JBOSS 5. I think I will move this to the JBOSS forum hopefully some JBOSS experts can help you with this.
 
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
The real question is why do you want to use JPA 2 (Hibernate 4.x) in an environment which doesn't support JPA 2 (JBoss AS 4.x)? Why not use Hibernate 3 if you want to stick wth JBoss AS 4.x. If at all you are using any JPA 2 specific features then it really means you need a runtime environment which supports JPA 2. JBoss AS 4.x is not that environment. You'll have to upgrade.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah Jaikiran, I've seen you weigh in on this issue many times. I've wrote my app in Hibernate b/c I didn't think my company was using an app server this out of date. Before I rewrite my app, you above all would know, can JBoss be instructed to use my Hibernate JARs over its own? In my JAR file, I have this file, META-INF/jboss.xml



but JBoss appears to be loading older versions of the Hibernate classes ...



I have verified the proper Hibernate classes are getting included in the JAR. Thanks, - Dave
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like your getting closer

That exception looks like it wants you to use AnnotationConfiguration which is deprecated in the version of hiberate you are using. You are probably using Configuration which is what you should be doing. The only thing I can think is one of the transitive dependencies are still being included by jboss and its not using what you have in your jar. Maybe rather than depending on maven to bundle the transitive dependencies to hibernate-core explicitly define them and verify that each one is in your jar.


 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic