-->
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.  [ 9 posts ] 
Author Message
 Post subject: SessionFactory and JNDI lookup under InitialContext
PostPosted: Wed Feb 04, 2004 3:01 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2004 4:53 pm
Posts: 28
Ok, here goes, figured I would allow my classes to lookup the sessionFactory which would simplify things --


Code:

<hibernate-configuration>

<session-factory name="java:comp/env/hibernate/SessionFactory" >       
        <property name="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</property>
        <property name="hibernate.connection.datasource">jdbc/DINTDS</property>
        <property name="hibernate.connection.username">ATA_CUSTOM</property>
        <property name="hibernate.connection.password">ATA_CUSTOM</property>
        <!--property name="hibernate.session_factory_name">java:comp/env/hibernate/SessionFactory</property -->

        <property name="show_sql">true</property>
        <property name="transaction.factory_class">
             net.sf.hibernate.transaction.JTATransactionFactory
        </property>

        <mapping resource="hibernateXML/Client.hbm.xml"/>
        <mapping resource="hibernateXML/Person.hbm.xml"/>
        <mapping resource="hibernateXML/Extra.hbm.xml"/>

        <class-cache class="com.test.test1.Client" usage="read-only"/>
        <class-cache class="com.test.test1.Person" usage="read-only"/>
        <class-cache class="com.test.test1.Extra" usage="read-only"/>
    </session-factory>

</hibernate-configuration>


I Tried accesing the jndi name via the InitialContext:
Code:
            Configuration conf = new Configuration().configure();
            String jndiLocation = "/hibernate/SessionFactory";
            Context  ctx = new InitialContext();
            sessionFactory = ( SessionFactory ) ctx.lookup(jndiLocation);

Code:
   String jndiLocation = "/hibernate/SessionFactory";
            Context  ctx = new InitialContext();
            sessionFactory = ( SessionFactory ) ctx.lookup(jndiLocation);


Both provided the following from the logs:
Code:
javax.naming.NameNotFoundException: hibernate/SessionFactory not found in One2Many/One2ManyWeb, there are no bound values


So, i switch to the following:
Code:
  sessionFactory = new Configuration().configure().buildSessionFactory();


With the following log:
Code:
13:44:47,011 DEBUG Configuration:952 - java:comp/env/hibernate/SessionFactory<-org.dom4j.tree.DefaultAttribute@9bf922 [Attribute: name resource value "hibernateXML/Client.hbm.xml"]


And I figured-- Ok Hibernate is JNDI aware, so I added some code to the lookup via InicialContext.lookup and still got a namingException...
What gives:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 4:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Tried without java:comp/env ? You DO have a writeable JNDI provider, do you?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 8:21 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2004 4:53 pm
Posts: 28
Using Orion server.....
And yes I tried as many combinations as possible...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 1:30 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
First validate whether and where the SessionFactory is bound in the JNDI tree. I don't know if Orion has a JNDI browser - you can always resort to plain java code.

Next check if you can lookup this object from your class. You haven't provided any information about the context from which you are invoking the method.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 10:17 am 
Beginner
Beginner

Joined: Tue Feb 03, 2004 4:53 pm
Posts: 28
drj wrote:
First validate whether and where the SessionFactory is bound in the JNDI tree. I don't know if Orion has a JNDI browser - you can always resort to plain java code.

Next check if you can lookup this object from your class. You haven't provided any information about the context from which you are invoking the method.


Good points:
I have built a web module contained with in an ear, yet all references are contained with-in the web module--
All jars are located with in the WEB-INF/lib..
The class that acceses Hibernate is contained with in the web-module.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 12:00 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2004 4:53 pm
Posts: 28
To add to things I added Atlassian's tools/jndi to the orion server and still can not find the jndi name --
the /tools/jndi allow one to view the jndi tree of the appserver...
http://www.atlassian.com/software/tools ... result.jsp



FA_INDY wrote:
drj wrote:
First validate whether and where the SessionFactory is bound in the JNDI tree. I don't know if Orion has a JNDI browser - you can always resort to plain java code.

Next check if you can lookup this object from your class. You haven't provided any information about the context from which you are invoking the method.


Good points:
I have built a web module contained with in an ear, yet all references are contained with-in the web module--
All jars are located with in the WEB-INF/lib..
The class that acceses Hibernate is contained with in the web-module.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 9:35 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2004 4:53 pm
Posts: 28
Ping Help please


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 1:09 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Ok - I'm not that familiar with Orion (actually not at all), but my next step would be to inspect the server logs at startup and check that the name is being bound to the JNDI tree.

On my (JBoss) server I set logging for net.sf.hibernate to DEBUG in the log4j.xml file
Code:
   <category name="net.sf.hibernate">
      <priority value="DEBUG"/>
   </category>

and got the following:
Code:
...
07:02:29,793 DEBUG [SessionFactoryImpl] Returning a Reference to the SessionFactory
07:02:29,803 DEBUG [NamingHelper] Bound name: java:/hibernate/Engagement
07:02:29,803 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: java:/hibernate/Engagement
...


The JNDI name that I specify in my properties is obviously java:/hibernate/Engagement

Also - from the docs:
Quote:
If you wish to have the SessionFactory bound to a JNDI namespace, specify a name (eg.
java:comp/env/hibernate/SessionFactory) using the property hibernate.session_factory_name. If this
property is omitted, the SessionFactory will not be bound to JNDI.



Why is your's commented out ?[/quote]


Top
 Profile  
 
 Post subject: Re: SessionFactory and JNDI lookup under InitialContext
PostPosted: Wed Feb 10, 2010 12:40 am 
Newbie

Joined: Wed Feb 10, 2010 12:27 am
Posts: 1
sounds so delicious! Thanks


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