-->
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.  [ 4 posts ] 
Author Message
 Post subject: JMX, Hibernate MBean, JBoss and JNDI....
PostPosted: Tue Jun 22, 2004 10:49 am 
Newbie

Joined: Tue Jun 22, 2004 9:26 am
Posts: 4
Hi.

I have a 'test' to see how JBoss and Hibernate work together. I have a Hibernate service running as an MBean in the JBoss server. My question is why I appear to need to configure a SessionFactory locally before issuing the lookup and subsequently getting a bind to a remote SessionFactory ( infact, is that what I am doing, and how does it work? )? The code is as below ( 'p' is the properties for Configuration instead of using an XML file... for testing ):

Configuration cfg = new Configuration();
cfg.addClass(User.class);
cfg.setProperties( p );
SessionFactory factory = cfg.buildSessionFactory();

factory = ( SessionFactory )ctx.lookup( "HibernateService" );
session = factory.openSession();

Many thanks, Bob.


Top
 Profile  
 
 Post subject: Shouldn't have to do this manually
PostPosted: Thu Jun 24, 2004 12:20 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
I'm presuming you've set up everything according to the example found here

http://www.hibernate.org/66.html

If you have, then you don't have to manually create the configuration object and add your classes. All you have to do is

Code:
InitialContext ctx = getContext();  //some method that creates your ctx
SessionFactory sf = (SessionFactory)ctx.lookup("java:/hibernate/HibernateFactory");


Once you've got a reference to the SessionFactory, you can create sessions and do whatever you want to with them. If this isn't working for you, then you may have missed something in your MBean setup.

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 8:47 am 
Newbie

Joined: Tue Jun 22, 2004 9:26 am
Posts: 4
MMmm...

Thanks! Is it reasonable to believe I can do this from outside of JBoss ( for example in an external unit test )? I'm using the JBoss context lib and have:

Properties properties = new Properties();
properties.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
properties.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );
properties.put( Context.PROVIDER_URL, "jnp://localhost:1099" );
InitialContext ctx = new InitialContext( properties );

sessionFactory = ( SessionFactory )ctx.lookup( "HibernateService" );

SessionFactory always comes back with null currently... I shall dig through the code to see why it doesn't bind - or have I done something obviously wrong?

Regards!


Top
 Profile  
 
 Post subject: Maybe your JNDI name is wrong?
PostPosted: Tue Jun 29, 2004 3:49 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
If the result of the JNDI lookup is null, the first thing I'd check is whether or not the JNDI look up name is correct. Have you changed the JndiName attribute from java:/hibernate/HibernateFactory to HibernateService in jboss-service.xml? If not, then change HibernateService to java:/hibernate/HibernateFactory in your code and see if that returns what you're looking for.

Otherwise, I'd have a look in the Jboss logs and see if anything occurred that caused Hibernate to fail to bind the SessionFactory into the JNDI tree. I've never tried to use a SessionFactory in this manner, so if it turns out to cause you any further problems, you might want to run your unit tests from within a test EJB. I'm assuming Hibernate already works from within Jboss though.

Good luck.

_________________
Mike Davison


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