-->
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.  [ 7 posts ] 
Author Message
 Post subject: Failed to lookup Hibernate SessionFactory in WebLogic
PostPosted: Wed Feb 16, 2005 7:07 am 
Newbie

Joined: Mon Nov 22, 2004 2:11 pm
Posts: 6
Hi,

I have read the post http://forum.hibernate.org/viewtopic.php?t=932394 which describes an interesting approach to reuse Hibernate Sesson instances withing an ejb server without the need of explicit session.flush() calls.
Unfortunately I can't successfully use the provided implementation of HibernateUtil inside WebLogic 8.1 (and Hibernate 2.1.6) since I receive a NameNotFoundException for java:/HibernateFactory inside the following method:
Code:
public static SessionFactory lookupSessionFactory() throws NamingException {
    InitialContext initCtx = new InitialContext();
    return (SessionFactory) initCtx.lookup("java:/HibernateFactory");
}

I am fairly sure that I miss some configuration that is needed to insert the Hibernate SessionFactory into the WebLogic JNDI context. Is this true? How can I do that?

Any help would really be appreciated
Thanks for your time.

Michael


My current hibernate.cfg.xml is as follows:
Code:
<hibernate-configuration>
  <session-factory name="java:/HibernateFactory">
    <property name="connection.datasource">jdbc/HibernateSampleDS</property>
    <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
    <property name="jta.UserTransaction">java:comp/UserTransaction</property>
    <property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
    <property name="show_sql">true</property>
    <property name="cache.use_query_cache">false</property>
    <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
    <mapping resource="mapping.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 9:48 am 
Newbie

Joined: Wed Sep 01, 2004 9:04 am
Posts: 18
Location: Enschede, Netherlands
Check out section 3.5.6 of the Hibernate reference:

http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html#configuration-optional-jndi

I think you need to specify the property hibernate.session_factory_name with value "java:/HibernateFactory", and the properties hibernate.jndi.url and hibernate.jndi.class to create the right InitialContext.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 12:43 pm 
Newbie

Joined: Mon Nov 22, 2004 2:11 pm
Posts: 6
Hi, thank you for the hint!
I changed the hibernate.cfg.xml and the source code accordingly. But I still receive the following exception:
Code:
javax.naming.NameNotFoundException: While trying to look up comp/env/hibernate/HibernateFactory in /app/ejb/EJBHibernateSampleClasses.jar#CustomerListSession.; remaining name 'comp/env/hibernate/HibernateFactory'
at sample.server.util.HibernateUtil.getSession(HibernateUtil.java:102)

I also tried "java:/HibernateFactory" as JNDI name. It did not work either.
Do you have any more hints?

Thanks for your time.

Michael

My hibernate.cfg.xml:
Code:
<hibernate-configuration>
  <session-factory name="java:comp/env/hibernate/HibernateFactory">
    <property name="connection.datasource">jdbc/HibernateSampleDS</property>
    <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
    <property name="jta.UserTransaction">java:comp/UserTransaction</property>
    <property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
    <property name="hibernate.jndi.class">weblogic.jndi.WLInitialContextFactory</property>
    <property name="hibernate.jndi.url">t3://192.168.1.1:7011</property>
    <property name="hibernate.session_factory_name">java:comp/env/hibernate/HibernateFactory</property>
    <property name="show_sql">true</property>
    <property name="cache.use_query_cache">false</property>
    <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.query.substitutions">true 1, false 0</property>
    <mapping resource="mapping.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


My code in HibernateUtil:
Code:
private SessionFactory getSessionFactory() throws NamingException {
    InitialContext initCtx = new InitialContext( );
    return (SessionFactory) initCtx.lookup("java:comp/env/hibernate/HibernateFactory");
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 12:55 pm 
Newbie

Joined: Wed Sep 01, 2004 9:04 am
Posts: 18
Location: Enschede, Netherlands
Try to replace: <session-factory name="java:comp/env/hibernate/HibernateFactory">

with:

<session-factory name="hibernate/HibernateFactory">


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 10:04 am 
Newbie

Joined: Mon Nov 22, 2004 2:11 pm
Posts: 6
Ok, I changed the config again, but it still does not work.
This is really strange. I wonder, if I have to make some configurations with the WebLogic console or the deployment descriptors...

Did you manage to successfully lookup a SessionFactory through JNDI within a Session Bean running on WebLogic 8.1?

Thanks for your time.

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 4:49 am 
Newbie

Joined: Wed Sep 01, 2004 9:04 am
Posts: 18
Location: Enschede, Netherlands
No, I didn't, just trying to check your configuration.

You also updated your config line

<property name="hibernate.session_factory_name">java:comp/env/hibernate/HibernateFactory</property>

to

<property name="hibernate.session_factory_name">hibernate/HibernateFactory</property>

?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 5:09 am 
Newbie

Joined: Mon Nov 22, 2004 2:11 pm
Posts: 6
I tried both versions.

Since I just want to imlement a HibernateUtil that synchronizes the hibernate session with transactions in a JTA environment of an ejb container transparently (as described in http://forum.hibernate.org/viewtopic.php?t=925357 and http://forum.hibernate.org/viewtopic.php?t=932394), and I can't find a code sample that works, I think I stop my research of the lookup problem now and move to Hibernate3 since it supports this feature (see at http://www.hibernate.org/245.html "Synchronizing Hibernate3 with JTA").

Anyway, thanks for your time.

Michael


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