-->
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.  [ 3 posts ] 
Author Message
 Post subject: Deploying Multiple Hibernate Projects in JBoss
PostPosted: Fri Jul 22, 2005 4:21 pm 
Newbie

Joined: Wed Jul 20, 2005 11:13 am
Posts: 1
I am using Hibernate 2.1.8, JBoss 3.2.5, MyEclipse and SQL database.

I am new to Hibernate and JBoss, but I have written a few applications that use hibernate. These work fine as long as I only have one of my war file deployed. If I deploy all of my war files and restart JBoss, the TomCat deployer will deploy each war in alphabetical order. The problem is that each war file becomes bound to the hibernate mapping of the first war file. The first application works fine, but the others give 'No Persistent Classes Found' errors since they have the wrong mappings.

I have searched this forum and the JBoss and MyEclipse forums, but have found very little on this problem except for references to ClassLoader issues with JBoss. I posted this question to the other forums and got replies from users having the same problem, but no one has posted a solution.

My question is will creating the hibernatedoclet and xml files found in http://www.hibernate.org/66.html fix this problem, or am I missing something? If having to create additional files to work with JBoss is the solution are there other application servers that work well with hibernate, that do not require the creation of additional files?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 1:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Need more info about how you bundle these webapps.


Top
 Profile  
 
 Post subject: solution to "multiple projects in one Jboss (3.2) insta
PostPosted: Thu Dec 22, 2005 8:00 am 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
Hi,

i had the same problem, do not know why is that (class loader?) but the solution that worked for me is to use unique configuration file; ie. create your session factory like this:

Code:
public class HibernateUtils {

    private static SessionFactory sessionFactory;
    private static ThreadLocal session;

    static {
   try {
            sessionFactory = new net.sf.hibernate.cfg.Configuration()
                .configure("/UNIQUE/NAME/OF/THE/RESOURCE")
      .buildSessionFactory();
       session = new ThreadLocal();
   }
   catch (Throwable ex) {
       org.apache.log4j.Logger.getRootLogger().fatal(ex);
       throw new ExceptionInInitializerError(ex);
   }
    }

   // ... the rest of the class ...

};


you can easily ensure uniqueness if you maintain your code in separate namespace ("org.somewhere.someapp") -> in that case i recommend

Code:
                .configure("/org/somewhere/someapp/hibernate.cfg.xml")


I used this solution in all my webapps and it works. Please notice the leading slash. hibernate 2.x is unhappy if missing, hibernate 3.x works even without it.

Hope this helps.

martin


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