Hi.

I am experimenting with having a Hibernate Service running as a JMX MBean per 
documentation on hibernate.org. All is fine - I can get the MBean housed in JBoss. I 
want to execute a test to see if I can play with the persistent objects/copies of 
those objects from a test-client that is not housed in JBoss. I had the idea that I 
could bind to the Session Factory via JNDI, then open a session, do stuff, then close 
a session. Simple enough test. I've just spent two days trying to get this working and 
kind of have now, but I don't understand exactly what is going on. Perhaps someone can 
enlighten me as to whether I am doing things correctly or not:

The only way I have found that works ( according to debug messages ) is to do the 
following steps:

1) Configure the initial context.

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);

2) Create a configuration.

Configuration cfg = new Configuration();

3) Set properties on it.

Properties p = new Properties();
p.put( "hibernate.session_factory_name", "HibernateService" );
p.put( "hibernate.jndi.url", "jnp://localhost:1099" );
p.put( "hibernate.jndi.class", "org.jnp.interfaces.NamingContextFactory" );
cfg.setProperties( p );

4) Build a SessionFactory.

SessionFactory factory = cfg.buildSessionFactory();

5) Reassign the factory with the resultant lookup from the InitialContext

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

6) Open session, do work, close session.

Session session = factory.openSession();
session.close();

I'm confused! Help?

Many thanks, Graeme.


-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to