Hi!
I'm using hibernate 3.0 , tomcat 5.0.28.
I'm trying to use jmx for HibernateService and StatisticsService.
It works fine for StatisticsService.
But i have some problems with HibernateService.
After narrowing the problems and trying different solutions (i know that tomcat comes with a read only jndi name space ) , i ended up with these configurations :
1. i use HibernateUtil.java
sessionFactory = new Configuration().configure().buildSessionFactory();
2.i use hibernate.cfg.xml
<session-factory>
<property name="show_sql">false</property>
<property name="hibernate.session_factory_name">hibernate/session_factory</property>
......
</session-factory>
3.when i start the application (without using hibernateService ) the folowing logs i get for the session factory building and jndi binding:
10:12:15,412 INFO Configuration:1159 - configuring from resource: /hibernate.cfg.xml
10:12:15,422 INFO Configuration:1130 - Configuration resource: /hibernate.cfg.xml
10:12:15,592 DEBUG DTDEntityResolver:42 - trying to locate
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
10:12:15,592 DEBUG DTDEntityResolver:53 - found
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
10:12:16,173 DEBUG Configuration:1116 - show_sql=false
10:12:16,173 DEBUG Configuration:1116 - hibernate.session_factory_name=hibernate/session_factory
.......
10:12:17,685 INFO Configuration:1271 - Configured SessionFactory: null
......
10:12:17,695 DEBUG Configuration:1047 - Preparing to build session factory with filters : {}
10:12:17,695 INFO Configuration:851 - processing extends queue
10:12:17,695 INFO Configuration:855 - processing collection mappings
......
10:12:17,715 INFO Configuration:864 - processing association property references
10:12:17,715 INFO Configuration:893 - processing foreign key constraints
......
10:12:19,057 INFO SessionFactoryImpl:140 - building session factory
10:12:19,057 DEBUG SessionFactoryImpl:149 - Session factory constructed with filter configurations : {}
10:12:19,057 DEBUG SessionFactoryImpl:152 - instantiating session factory with properties:{here are the properties , if needed i will post them }
.....
10:12:38,795 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
10:12:38,875 DEBUG SessionFactoryObjectFactory:76 - registered: 2c90a8b30474014b0104740198b50000 (hibernate/session_factory)
10:12:38,875 INFO SessionFactoryObjectFactory:86 - Factory name: hibernate/session_factory
10:12:38,875 INFO NamingHelper:26 - JNDI InitialContext properties:{}
10:12:38,875 DEBUG NamingHelper:48 - binding: hibernate/session_factory
10:12:38,875 DEBUG NamingHelper:58 - lookup: hibernate
10:12:38,905 INFO NamingHelper:68 - Creating subcontext: hibernate
10:12:38,905 DEBUG NamingHelper:73 - binding: session_factory
10:12:38,905 DEBUG SessionFactoryImpl:524 - Returning a Reference to the SessionFactory
10:12:38,905 DEBUG NamingHelper:76 - Bound name: hibernate/session_factory
10:12:38,945 INFO SessionFactoryObjectFactory:91 - Bound factory to JNDI name: hibernate/session_factory
10:12:38,945 WARN SessionFactoryObjectFactory:101 - InitialContext did not implement EventContext
10:12:38,945 DEBUG SessionFactoryImpl:249 - instantiated session factory
10:12:39,396 INFO SessionFactoryImpl:366 - Checking 0 named queries
10:12:39,426 DEBUG HibernateUtil:34 - before Building the configuration in Hibernate util ...
10:12:39,526 DEBUG SessionImpl:229 - opened session at timestamp: 4581940262608896
.......
And now , the problem at which i arrived is that when i'm trying to use the HibernateService i get a classCastException.
i'm trying to stop the service(after taking care that the session factory is bounded) :
......
System.out.println("boundName = "+boundName);
Object obj = context.lookup(boundName);
System.out.println(obj +" , class = "+obj.getClass());
( (SessionFactory) obj ).close();
....
and i get this logs
......
boundName = hibernate/session_factory
Reference Class Name: org.hibernate.impl.SessionFactoryImpl
Type: uuid
Content: 2c90a8b30474014b010474742c060001
, class = class javax.naming.Reference
12:18:16,804 WARN HibernateServiceMBean:67 - exception while stopping service
java.lang.ClassCastException
at org.hibernate.jmx.HibernateService.stop(HibernateService.java:63)
....
I hope all the needed detail are here.
If not i am ready to give any other details.
What i don't understand is :
--- from the logs of building configuration is clear that in jndi is registered a reference of the object session_factory.
-- but then , the stop method tries to access directly the object.(and this how i get the classCastException). why ?(shouldn't it try to acces the reference ?)
Is it a bug ? Or am i doing something totaly wrong ?
Thank you very much for any answer !
PS : one thing that i don't understand also is why it works the binding to jndi. As i understood the tomcat has a read only jndi But still , as i can see, it binds the object. i tried also another variation of hibernate.cfg.xml with the line
<session-factory name="hibernate/session_factory" >
and this way i get the error that tomcat jndi is read only ...
Thanks again !