-->
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: fscontext lookup returns null
PostPosted: Tue Oct 03, 2006 3:10 pm 
Newbie

Joined: Tue Oct 03, 2006 2:43 pm
Posts: 4
I am getting the following debug statement from when executing lookup(). The retunr object is null.

14:36:44,518 WARN SessionFactoryObjectFactory:148 - Not found: 2c91e18a0e0f3f2d010e0f3f30a20000


I did run first time to bind:


SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

My hibernate.cfg.xml:

<session-factory> <!-- name="hibernate.session_factory_name"> -->

<property name="hibernate.session_factory_name">java:hibernate/SessionFactory</property>
<property name="hibernate.jndi.class">com.sun.jndi.fscontext.RefFSContextFactory</property>
<property name="hibernate.jndi.url">file:///moje/visualization/jndi</property>

Program that retrieves SessionFactory:

Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
env.put (Context.PROVIDER_URL,"file:///c:/moje/visualization/jndi");
InitialContext initialContext = new InitialContext(env);
SessionFactory o = (SessionFactory) initialContext.lookup("java:hibernate/SessionFactory");

SessionFactory o = (SessionFactory) initialContext.lookup("java:hibernate/SessionFactory");

The fscontext file .bindings:

#This file is used by the JNDI FSContext.
#Tue Oct 03 13:36:09 EDT 2006
java\:hibernate/SessionFactory/ClassName=org.hibernate.impl.SessionFactoryImpl
java\:hibernate/SessionFactory/RefAddr/0/Encoding=String
java\:hibernate/SessionFactory/RefAddr/0/Type=uuid
java\:hibernate/SessionFactory/RefAddr/0/Content=2c91e18a0e0f3f2d010e0f3f30a20000
java\:hibernate/SessionFactory/FactoryName=org.hibernate.impl.SessionFactoryObjectFactory

I have tried an example from jndi tutorial with fscontext and I can bind and lookup with no problems. With Hibernate, I am getting null from lookup. From what I see the program finds the name in jndi (if I misspell it would give NameNotFoundException). For some reasons, it has a problem with uuid?

Hibernate 3.2. jdk1.5

Eugene


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 3:21 pm 
Newbie

Joined: Tue Oct 03, 2006 2:43 pm
Posts: 4
I though this info also may be useful. This is the log from
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

5:17:56,241 INFO SessionFactoryImpl:159 - building session factory
15:17:57,062 INFO SessionFactoryObjectFactory:86 - Factory name: java:hibernate/SessionFactory
15:17:57,082 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming.provider.url=file:///moje/visualization/jndi, java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory}
15:17:57,112 INFO SessionFactoryObjectFactory:91 - Bound factory to JNDI name: java:hibernate/SessionFactory
15:17:57,112 WARN SessionFactoryObjectFactory:101 - InitialContext did not implement EventContext


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 3:54 pm 
Newbie

Joined: Tue Oct 03, 2006 2:43 pm
Posts: 4
When executing lookup, the "Not found.." message comes from:

public class SessionFactoryObjectFactory {
public static Object getInstance(String uid) {
log.debug("lookup: uid=" + uid);
Object result = INSTANCES.get(uid);
if (result==null) {
log.warn("Not found: " + uid);
log.debug(INSTANCES);
}


INSTANCES is a HashMap. I guess the INSTANCES has not been prepopulated by the previous code in lookup.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 4:29 pm 
Newbie

Joined: Tue Oct 03, 2006 2:43 pm
Posts: 4
Soon, I am going to answer my own question. If I am correct, the INSTANCES hashmap is supposed to be in memory for some reasons. So, in the example below, the first lookup fails with Not Found (As INSTANCES is empty), the second lookup finds Sessionfactory (just to be clear, executing second time gives the same result - the first lookup returns null).

SessionFactory o = (SessionFactory) initialContext.lookup("java:hibernate/SessionFactory");


SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

o = (SessionFactory) initialContext.lookup("java:hibernate/SessionFactory");

What's the design rationale to rely on static HashMap to retain objects in memory? I am running my program in a plain JVM so I do not expect to retain anything in memory.


Top
 Profile  
 
 Post subject: Re: fscontext lookup returns null
PostPosted: Mon Jun 15, 2009 6:01 am 
Newbie

Joined: Mon Jun 15, 2009 5:45 am
Posts: 3
EDITED

Hi ek
I'm currently running into the exact same problem as you did. Doing a lookup for the Hibernate SessionFactory, the fscontext JNDI implementation returns null instead of the expected SessionFactory.
I did the same tests as you did :
- trying with a misspelled name returns NameNotFoundException instead of null
- I can bind and lookup with no problems some other test objects
- the .binding file is present on the file system where expected

It seams that other people have had great success with this approach as we can read here :
viewtopic.php?f=1&t=978070&p=2360776&hilit=standalone+JNDI+sessionfactory#p2360776
and here
viewtopic.php?f=1&t=963485&hilit=standalone+jndi+sessionfactory

so I was wondering if you did find any solution to that strange problem that is getting on my nerves for a few days now.

Please let me know if you did succeed even if you don't remember how :)

Thanks a lot in advance.

EDITED:
Ok, so I guess we are in the 'I reply to myself' thread ;)

What you mean is that you have to configure hibernate (most probably with a different config, much simpler containing only the jndi stuf) BEFORE your lookup gets any chance to return a SessionFactory that's not null. So, no need to use a 'real' lookup just initialise your Hibernate with a config file that contains the JNDI name.

What i'm trying to do is this :
We have many users on one Windows server each running their own Eclipse RCP app in a different Windows session (via Terminal Server). Every time a user starts his app, the time needed to start the hibernate SessionFactory makes that our app is slow to start.
I figured that binding the SessionFactory to a JNDI context would do that the hibernate startup would be done once for all users speeding up every app startup. Just like we do in a application server environment. Not to mention the use of common and persistent caches (Queries, second level) for all users.

What i get now, is the exact same slow startup time because i still have to configure the hibernate SessionFactory. I don't even really know if the SessionFactory object i get is really the one bound in the JNDI context by my previous bind...

Maybe am I just misunderstanding something? Can anyone give me a hint ???

I would really, really appreciate that, thanks to all

My conf :
hibernate 3.3.0.SP1
fscontext 1.2 beta 3
windows XP pro SP3 in VMWare Player / XP pro SP3


Top
 Profile  
 
 Post subject: Re: fscontext lookup returns null
PostPosted: Wed Jun 24, 2009 5:22 am 
Newbie

Joined: Mon Jun 15, 2009 5:45 am
Posts: 3
Up?
Anyone had any success with a JNDI bound SessionContext with the fscontext implementation?
Please help!


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.