-->
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 / HibernateService / session factory / jndi
PostPosted: Mon Jun 13, 2005 2:54 am 
Newbie

Joined: Mon Jun 13, 2005 2:19 am
Posts: 5
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 !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 9:21 am 
Newbie

Joined: Mon Jun 13, 2005 2:19 am
Posts: 5
I realized that there could be a confusion in the details that i gave.
To summarize :
I try to invoke the method stop() from the class HibernateService.java using jmx. The jmx works fine. The problem is that it can not find the object session factory. And this is happening because at the name session_factory it finds a reference object to the object session factory.

the code from method stop() is (a little transformed with System.out.println) :

......
System.out.println("boundName = "+boundName);
Object obj = context.lookup(boundName);
System.out.println(obj +" , class = "+obj.getClass());
( (SessionFactory) obj ).close();
....

and after i invoke it , 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)
....




Thanks a lot again for any comments !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 2:00 am 
Newbie

Joined: Mon Jun 13, 2005 2:19 am
Posts: 5
Hi!

I'm still trying to figure out what am i doing wrong ...

i have a work around ... but i don't know if is the right thing to do...

Again :
- i'm trying to invoke the method stop() :

public void stop() {
log.info("stopping service");
try {
InitialContext context = NamingHelper.getInitialContext( buildProperties() );
( (SessionFactory) context.lookup(boundName) ).close();
//context.unbind(boundName);
}
catch (Exception e) {
log.warn("exception while stopping service", e);
}
}

But i get a class cast exceptionb because the line

context.lookup(boundName)

returns me an object of type javax.naming.Reference.

I did not find anything wrong .. so i guess it returns me the right object.


The work around would be to modify the stop() method in this way :

1. i have the reference
2. i get uuid , and also the factory object
3. and having the factory object and the uuid i can get the object i need : that is the session factory ...(SessionFactoryImpl)


Is that the right think to do ?
Or again , i did something wrong somewhere ?

Thanks!


Top
 Profile  
 
 Post subject: Anybody using jmx/tomcat/HiberanteService ?
PostPosted: Wed Jun 15, 2005 2:08 am 
Newbie

Joined: Mon Jun 13, 2005 2:19 am
Posts: 5
Ok guys , this is my last question concerning this issue ...

Has anybody used jmx for HibernateService.java using tomcat 5.0.x and hibernate 3.0 ?

Thanks a lot !


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.