-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to obtain Configuration when using JBoss Mbean?
PostPosted: Mon Apr 26, 2004 1:02 pm 
Newbie

Joined: Mon Apr 26, 2004 12:51 pm
Posts: 3
Location: Stuttgart, Germany
Hi,

I am using Hibernate 2.1.2 with the JBoss-service Mbean, which works well.
Now I would like to start a SchemaUpdate from an initializer servlet.
All examples go
Configuration cfg= ...
new SchemaUpdate(cfg).execute();

How do I get the Configuration object?

If i understand it correctly, then I would only need the properties, which are present in SessionFactory, then I could do
Configuration cfg = new Configuration();
cfg.properties(SessionFactory.getProperties());
new SchemaUpdate(cfg)...

Would this be ok?
Is there a simpler way?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
why don't you use hbm2ddl.auto=update?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 4:07 am 
Newbie

Joined: Wed Mar 03, 2004 7:11 am
Posts: 6
I have stored the Configuration object in the JNDI tree to be
able to retrieve it later. But this requires the Configuration object
to be Serializable. I have submitted a patch to the JIRA (HB-492)
to make this possible.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 8:59 am 
Newbie

Joined: Mon Apr 26, 2004 12:51 pm
Posts: 3
Location: Stuttgart, Germany
Do you have an example on how to integrate it in jboss-service.xml ?
Or do I need to add a hibernate.properties file somewhere (where?)
Thanks
Heiko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 9:18 am 
Newbie

Joined: Wed Mar 03, 2004 7:11 am
Posts: 6
pilhuhn wrote:
Do you have an example on how to integrate it in jboss-service.xml ?
Or do I need to add a hibernate.properties file somewhere (where?)
Thanks
Heiko


To be able to store the configuration in JNDI in Jboss, you have
to modify the existing HibernateService. Unfortunately, it
is not easy to extend this class as it contains package
method that you have to copy in order to be able to access
them. To store the configuration, it is needed to redefine the
buildSessionFactory method to add the binding of the
configuration and the start method to call the new method.

I include some of my methods.

Code:


    protected String getConfigurationJndiName() {
        return getJndiName() + "Configuration";
    }

    /**
     * Create and bound the session factory and the configuration in JNDI.
     *
     * @return a <code>SessionFactory</code> value
     * @exception HibernateException if an error occurs
     */
    protected SessionFactory buildSessionFactory() throws HibernateException {
        log.info( "Starting service at JNDI name: " + getJndiName() );
        log.info( "Service properties: " + getProperties() );

        Configuration cfg = new Configuration().addProperties( getProperties() );

        String[] mappingFiles = parseResourceList( getMapResources() );
        for ( int i=0; i<mappingFiles.length; i++ ) {
            cfg.addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() );
        }

        try {
            InitialContext context = NamingHelper.getInitialContext( getProperties() );
            log.debug("Binding the configuration under the name " +
                      getConfigurationJndiName());
            NamingHelper.bind(context, getConfigurationJndiName() , cfg);
        } catch (NamingException e) {
            throw new HibernateException(e);
        }
       
        return cfg.buildSessionFactory();
    }


I hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 10:49 pm 
Newbie

Joined: Tue May 04, 2004 3:32 pm
Posts: 16
Location: Iowa
I am trying to build a new SessionFactory at runtime for multiple datasources. Since I use Jboss and hibernate service, I don't have the config file. The strategy you metioned is very interesting. But it requires a patch, doesn't it?
What I am thinking is that I use the JMX MBeanServer API to access an existing SessionFactory and then create a new instance of hibernate mbean based on the attributes of the existing one. The only attributes I need to change are jndi name and datasource name. After this, I can see the newly created mbean from jmx-console. But I got a problem which I am working on.
Do you think clone the existing mbean instance will work?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:23 am 
Newbie

Joined: Wed Mar 03, 2004 7:11 am
Posts: 6
ryang5 wrote:
I am trying to build a new SessionFactory at runtime for multiple datasources. Since I use Jboss and hibernate service, I don't have the config file. The strategy you metioned is very interesting. But it requires a patch, doesn't it?


Yes, this is true for hibernate 2.1. I think hibernate 2.2
has a Serializable Configuration object by default.

ryang5 wrote:
What I am thinking is that I use the JMX MBeanServer API to access an existing SessionFactory and then create a new instance of hibernate mbean based on the attributes of the existing one. The only attributes I need to change are jndi name and datasource name. After this, I can see the newly created mbean from jmx-console. But I got a problem which I am working on. Do you think clone the existing mbean instance will work?


I do not know if cloning is the best approach (MBeans have
a life cycle, so cloning the internal state can lead to problems), but
creating a new Mbean from the original one and registering it in
the JMX server should work without any problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.