-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to get another web app's SessionFactory?
PostPosted: Tue Jan 31, 2006 12:56 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Hi everyone:

Could I get a sessionfactory of another webapp's? (I use Tomcat5) I have two web applications,WebApp1 and WebApp2. They use hibernate but using different databases. Webapp1 use hibernate1.cfg.xml as the following:


Code:
<session-factory>
......................................................................
      <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
      <property name="connection.url">jdbc:mysql://192.168.1.17:3306/user</property>
............................................................................


webapp2 use hibernate2.cfg.xml in another application:
Code:
<session-factory>
......................................................................
      <property name="connection.driver_class">com.oracle.jdbc.OracleDriver</property>
      <property name="connection.url">jdbc:oracle@thin:192.168.1.17:3306/user</property>
............................................................................


Now , I want to operate the sessionfactory1 in webapp2
How to do it? I mean that it is possible to get the sessionfactory1 in webapp2? I want to bind the sessionfactory1 to jndi tree,then how to get the sessionfactory1 in my second webapp2?
Thks!

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 3:25 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello,

you can bind them to JNDI and retrieve them form there.
I think in the Wiki there are information about JNDI binding.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject: :(
PostPosted: Wed Feb 01, 2006 10:22 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
LaLiLuna wrote:
Hello,

you can bind them to JNDI and retrieve them form there.
I think in the Wiki there are information about JNDI binding.

Regards Sebastian


I know how to build the sessionFactory to local webapp's jndi tree,and I could get the sessionfactory from local web context(jndi tree). But how to get another webapp's jndi handler? I mean that how to get webapp1's jndi object from webapp2's context? Could I do this by this way:?

Code:

Context webapp2Context= new InitialContext();
sessionFactory =
(SessionFactory) webapp2Context.lookup("webapp1/jndi/HibernateSessionFactory");


Could I get the jndi tree cross Tomcat context?
But it seems don't work. Have you try it before? Thks!

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 11:04 am 
Newbie

Joined: Wed Feb 01, 2006 10:22 am
Posts: 6
there are multiple scopes in Tomcat's JNDI tree (IIRC). There are app specific resources, and there are global resources. Global resources are available for lookup by all apps. Did you try making both session factories available in the global context? This should allow you to look up both of them from either app.


Top
 Profile  
 
 Post subject: :(
PostPosted: Wed Feb 01, 2006 10:06 pm 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
sai-brian wrote:
there are multiple scopes in Tomcat's JNDI tree (IIRC). There are app specific resources, and there are global resources. Global resources are available for lookup by all apps. Did you try making both session factories available in the global context? This should allow you to look up both of them from either app.


But how to make the webapp1's session factories available in the global context? It is binded to webapp1's context already. Is there any easy method to bind it to the tomcat 's global resources? I don't find any docs about how to bind object to global context, because as I know,tomcat's context is ready-only, how do you bind any object to it? Thks

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 5:05 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
did you try to google?
I am not sure but this may help.
http://www.hibernate.org/114.html?cmd=c ... stnode=896
You should consider to rate if or postings helped.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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