This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes Jboss hibernate service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Jboss hibernate service" Watch "Jboss hibernate service" New topic
Author

Jboss hibernate service

Pusti rajkumar
Greenhorn

Joined: Mar 29, 2006
Posts: 1
Hi

i have two different ears being deployed in the Jboss.
I am trying to start a hibernate service in both of them.
If iam doing so , the jboss throws a exception that trying to start the service that has been initialised already.

I am have respective persitance.sar built in the ears which has a Jboss_service.xml and jboss_app.xml has been configured to start the service.

Is there is any way to solve this issue
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
where is your hibernate jar (or where are your hibernate jars )? JBoss has some ClassLoader issues, so you have to be careful about how you deal with jars and classpaths.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9912
    
158

I guess, the service name mentioned in the mbean tag(in jboss-service.xml) has the same name in both the applications. As a result, while deploying the Hibernate service in the second application, it is throwing an error. Please post the jboss-service.xml(or may be something like *-service.xml) present in your hibernate service package(I dont remember the syntax of the mbean tag, so will be able to help you out only after having a look at the file).
[ March 29, 2006: Message edited by: jaikiran pai ]

[My Blog] [JavaRanch Journal]
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Hi there,
I am also facing the same problem. Following are the things tried by me:
1) Having the same sessionFactory name in both the hibernate-service.xml files but it does not work.
2) Setting the ScanForMappingsEnabled attribute to true. When i do this, i get the exception that trying to start the service that has been initialised already.



Can anybody throw some light as to am i missing something or is it a bug with hibernate ....?


~Madhuri
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9912
    
158

Originally posted by madhuri madhuri:
1) Having the same sessionFactory name in both the hibernate-service.xml files but it does not work.


You should have different service names in the 2 hibernate-service.xml files.

Something like the following:

hibernate-service.xml in myFirstApp:


hibernate-service.xml in mySecondApp:


Try it out
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9912
    
158

Forgot to change the session Factory name. do it as follows:

hibernate-service.xml in myFirstApp:


hibernate-service.xml in mySecondApp:
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Hello Jaikiran,
Thanks for the suggestion but that did not work.

Well the scenario is like this,
I have two ear files. Say myApp1.ear and myApp2.ear
I have class A in myApp1.ear
I have class B in myApp2.ear (Actually has a war file also as this part is a web application)

Now, my application demands that i need to have a join (many-to-many relationship) between class A and class B.

When i tried the suggestions you had given having different session factory names, it becomes a class loader issue as I am accessing the class A present in myApp1.ear from the web app.

I hope This makes sense. Can anybody suggest any solutions for this....?

Thanks,
Madhuri
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Now, my application demands that i need to have a join (many-to-many relationship) between class A and class B

If your application demands this, then why are the two classes not in the same EAR?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Originally posted by Paul Sturrock:

If your application demands this, then why are the two classes not in the same EAR?


I know that it makes life easier having the two classes in the same EAR. The Web application is a new feature and just requires only one class from the other EAR file. It doesn't make sense to have all the classes that are not required for the web app be loaded along with this one class. If i had just this one class on the web app side, I will be duplicating the data leading to many issues as the data I am handling is critical and deals with recording ingests for a show.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


It doesn't make sense to have all the classes that are not required for the web app be loaded along with this one class

Absolutely. But if you are joining between ClassA, which is one EAR, and ClassB then ClassB is required for the Web App (unless that is you start adding things to the app server's classpath, but that's a bad idea).
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Originally posted by Paul Sturrock:

Absolutely. But if you are joining between ClassA, which is one EAR, and ClassB then ClassB is required for the Web App (unless that is you start adding things to the app server's classpath, but that's a bad idea).

After a lot of thinking i came up with this solution.
I am writing a work around for this by having an EJB in EAR1 to access ClassA from the Web App. But its very ugly and also hurts the performance. Was wondering if anybody had faced this problem earlier? Is it possible with Hibernate or is it a bug ....?

Cheers,
Madhuri
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Is it possible with Hibernate or is it a bug ....?

No. And its definately not a bug, you are just trying to use Hibernate in a way it is not supposed to work.

Suppose you have one SessionFactory which is used by two applications. You can use a Hibernate service in JBoss to bind this SessionFactory in to JNDI and make it available to both applications. However, as is the case with any JNDI bound resource the application itself will have to be able to load the classes that are bound in JNDI and for that you will need every class in your SessionFactory in the classpath of both applications. What we do is create our Hibernate DAO layer as a seperate deployable component (a Jar file) and deploy it to every application that uses it.
 
Don't get me started about those stupid light bulbs.
 
subject: Jboss hibernate service
 
Similar Threads
configuring eclipse with jboss and tomcat
ORM vs JDBC
Deploy Hibernate2.1 on JBoss 3.2.3
Run jboss after Logoff from windows
Hibernate JBoss Transaction