-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problem Accessing HibernateFactory Across JVMs
PostPosted: Thu Jul 22, 2004 5:04 pm 
Newbie

Joined: Thu Jul 15, 2004 4:58 pm
Posts: 5
Hibernate v2, JBoss 3.2.5

i have written a session bean as a data access object using hibernate. the hibernate.sar is deployed using the jndi name ecommerce/hibernate. This name is visible in the standalone ejb client's context (separate jvm). However a lookup for new InitialContext().lookup("ecommerce/hibernate") returns null with the following in the log:

Code:
[main] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory  - initializing class SessionFactoryObjectFactory
[main] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory  - JNDI lookup: ecommerce/hibernate
[main] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory  - lookup: uid=2a4c3506fde89f8400fde89f895e0000
[main] WARN  net.sf.hibernate.impl.SessionFactoryObjectFactory  - Not found: 2a4c3506fde89f8400fde89f895e0000
[main] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory  - {}


this is because the SessionFactoryObjectFactory is apparently a singleton and it's method getInstance(String uid) looks up the uid reference in it's internal HashMap: and in this case the reference is not going to be present in the client's singleton, because it's in the app server's singleton.

i would like this to work, otherwise i can't use lazy init's for my collections as the POJO can't lookup the SessionFactory because of the above mentioned reasons.

is there a way around it? please, gurus, help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:06 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It will only do the UUID lookup if the SessionFactory is not in JNDI.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:17 pm 
Newbie

Joined: Thu Jul 15, 2004 4:58 pm
Posts: 5
traversing the jndi tree from the client shows that it is bound:

Code:
[main] DEBUG com.unisource.ec.test.AccountDAOTest  - >ejb
[main] DEBUG com.unisource.ec.test.AccountDAOTest  -   -ProductDAO: $Proxy49:ecommerce/ejb/ProductDAOHome
[main] DEBUG com.unisource.ec.test.AccountDAOTest  -   -AccountDAO: $Proxy42:ecommerce/ejb/AccountDAOHome
[main] DEBUG com.unisource.ec.test.AccountDAOTest  - -hibernate: net.sf.hibernate.impl.SessionFactoryImpl:Reference Class Name: net.sf.hibernate.impl.SessionFactoryImpl


what am i doing wrong? did i deploy the .sar incorrectly? is there another way to bind the factory instance in jboss in addition to using the jboss-service.xml:

Code:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService"
       name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
    <depends>jboss.jca:service=RARDeployer</depends>
    <depends>jboss.j2ee:service=EjbModule,module=ecommerce-ejb-account.jar</depends>
    <depends>jboss.j2ee:service=EjbModule,module=ecommerce-ejb-product.jar</depends>
    <depends>jboss.jca:service=LocalTxCM,name=ecommerce/ds</depends>
    <attribute name="MapResources">
      mappings/System.hbm.xml,
      mappings/Account.hbm.xml,
      mappings/Product.hbm.xml
      </attribute>
    <attribute name="JndiName">ecommerce/hibernate</attribute>
    <attribute name="Datasource">java:/ecommerce/ds</attribute>
    <attribute name="Dialect">net.sf.hibernate.dialect.OracleDialect</attribute>
    <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
    <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
    <attribute name="UseOuterJoin">false</attribute>
    <attribute name="ShowSql">false</attribute>
    <attribute name="UserTransactionName">UserTransaction</attribute>
    <attribute name="MaxFetchDepth">3</attribute>
</mbean>
</server>


simply put, i just need to be able to declare my collections as lazy for obvious performace reasons but i can't do that because the client throws a lazy init exception:

Code:
[main] ERROR net.sf.hibernate.LazyInitializationException  - Failed to lazily initialize a collection - no session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
   at net.sf.hibernate.collection.Set.toString(Set.java:217)
   at java.lang.String.valueOf(String.java:2131)
   at java.io.PrintStream.print(PrintStream.java:462)
   at java.io.PrintStream.println(PrintStream.java:599)
   at com.unisource.ec.test.AccountDAOTest.main(Unknown Source)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The solution for this is not a SessionFactory in JNDI, but

a) retrieve all information required before closing the Session
b) keep the Session open until all lazy properties are initialized (only possible in a single VM scenario)
c) manually initialize using Hibernate.initialize()

The first one is prefered, using "fetch" in HQL and the FetchMode in Criteria as runtime fetching strategies (overriding the defaults in the mapping file).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:45 pm 
Newbie

Joined: Thu Jul 15, 2004 4:58 pm
Posts: 5
a) fetching won't work because it's a one-to-many set, and there's no HQL to modify:

Code:
    <set name="legacyInfos"
         table="LT_LEGACY_XREF"
         cascade="all"
         inverse="true"
         lazy="true">
      <key column="OID"/>
      <one-to-many class="com.unisource.ec.schema.account.LegacyAccountInfo"/>
    </set>


b) single vm is not applicable here

c) i'm keeping the session open, i.e., i only call session.disconnect(), and i only call session.close() upon an ejbRemove(). i was hoping this would solve the problem, but it doesn't help because of the session factory lookup problem.

so basically, what you're saying what i'm trying to do is not possible.

i would not like to completely populate the object unless the client code explicity calls the getters that return the lazy collections, ofcourse, for performance reasons -- wasn't that your idea behind lazy collections anyway?

PS: since, hibernate is going to be a core part of the new jboss (4?), are you guys planning to write a hibernate/ejb best practices framework document? that would help a lot of people out, it would have save me a couple of weeks.

thanks so much for your help, unless there's more you could add to resolve my dilemma


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:47 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
PS: since, hibernate is going to be a core part of the new jboss (4?), are you guys planning to write a hibernate/ejb best practices framework document? that would help a lot of people out, it would have save me a couple of weeks.


This is called "Hibernate in Action". There is no easy answer to your problem.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:54 pm 
Newbie

Joined: Thu Jul 15, 2004 4:58 pm
Posts: 5
i'm definitely buying the book. BTW, my previous comment was in no way trying to belittle your efforts. i think hibernate ROCKS!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:56 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It was just a hint that you have to study some more, especially about the part that there was "no HQL" to solve this issue. It's the only (and good) solution, but I think you might understand it in a bigger context.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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