-->
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.  [ 9 posts ] 
Author Message
 Post subject: proble getting JBoss started
PostPosted: Mon Dec 15, 2003 4:52 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
I am trying to configure my mbean as per the documentation and I am getting the error below :


(javax.management.InstanceNotFoundException: jboss.jca:service=HibernateFactory, name=HibernateFactory is not registered.)
Would anybody be able to tell me why I cannot start my JBoss when I add this entry to my jboss-service.xml.

I am using the mbean entry below and have gone through the previous steps as outlined in the document http://www.hibernate.org/66.html



<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">mappings/mytasks.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 10:46 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Can you give the full log/stack trace?



Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 12:25 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
thanks for getting back to me. I've gotten past my original problem, but now when I'm when I do the buildSessionFactory api I get messages in my console window. The first message indicates no properties are found, yet I have tried the mbeans approach as well as putting the hibernate.cfg.xml under my META-INF directory..each without any luck

Shouldn't the hibernate.cfg.xml go in the META-INF directory ? Is so, any idea why the console window is telling me that hibernate.properies is not found ?

thanks,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 1:12 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Using the MBean supercedes the need for a separate hibernate.cfg.xml or hibernate.properties file being available. My start up of JBoss has an INFO message about not finding hibernate.properties, and everything works fine.

When running in JBoss with the MBean approach, you do not need to explicitly buildSessionFactory. Your code should look like:

Code:
    // The hibernateResource string is the JNDIName attribute you specifed
    // in the MBean descriptor

    private static String hibernateResource = "java:/HibernateFactory";
    private static SessionFactory factory = null;

    // In a session bean...

    public void ejbCreate() throws CreateException {
        if (factory == null) {
            try {
                Context jndiContext = new InitialContext();
                factory = (SessionFactory) jndiContext.lookup(hibernateResource);
            } catch (Exception e) {
                throw new CreateException(e.getMessage());
            }
        }
    }

    // A method accessing Hibernate in the session bean

    public String getValidUser(String username) {
        Session aSession = null;

        try {
            aSession = factory.openSession();

            return UserService.getUser(aSession, username);

        } catch (Throwable t) {
            log.error("getUser: caught exception", t);
        } finally {
            if (aSession != null)  {
                try {
                    aSession.flush();
                    aSession.close();
                } catch (HibernateException he) {
                    log.error("Abort: HibernateException on close", he);
                }
            }
        }
        return null;
    }


You can also use Hibernate Transactions here, too.

Code:
    public String getValidUser(String username) {

        Session session = null;
        Transaction tx = null;

        try {
            session = factory.openSession();
            tx = session.beginTransaction();

            // Do Hibernate work

            tx.commit();
        }
        catch (Throwable e) {
            if ( tx != null ) {
                try {
                    tx.rollback();
                } catch (Exception ex) {
                    logger.logError("Exception rolling back", ex);
                }
            }

            if ( session != null && session.isOpen() )  {
                try {               
                    session.close();
                } catch (HibernateException he) {
                    logger.logError("Hibernate Exception closing session", he);
                }
            }
            throw new PipelineException("Error processing indexes", e);
        }
        finally {
            if ( session != null && session.isConnected() ) {
                try {
                    session.close();   
                } catch (HibernateException he) {
                    logger.logError("Abort: HibernateException on close",
                                    he);
                }
            }
        }
       
    }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 1:53 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
thanks.
I must be missing something. Im trying the mbean approach and when I do the api :
try{
factory = (SessionFactory) context.lookup "java:/hibernate/HibernateFactory");
}
catch ( Exception e ){



I get a detail message saying that "Hibernate is not bound "

I tried looking at the jmx-console as well and do not seeing anything relating to hiberate running.

I added the jboss-service.xml to my META-INF subdirectory. I made a copy of the default jboss-service.xml file and adding the <mbean> section that is explained in the Using Jboss with Hibernate article :

<!-- ==================================================================== -->
<!-- Hibernate -->
<!-- ==================================================================== -->
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">mappings/mytasks.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>

thanks,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 2:33 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Can you post the section of your JBoss server.log that shows the Hibernate start up?

Here is an example of mine:

Code:
[net.sf.hibernate.jmx.HibernateServiceMBean] starting service at JNDI name: java:/GWHibernateFactory
[net.sf.hibernate.jmx.HibernateServiceMBean] service properties: {
  hibernate.transaction.manager_lookup_class=net.sf.hibernate.transaction.JBossTransactionManagerLookup,
  hibernate.cache.provider_class=net.sf.ehcache.hibernate.Provider,
  hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect,
  hibernate.use_outer_join=true,
  hibernate.session_factory_name=java:/GWHibernateFactory,
  hibernate.connection.datasource=java:/galenworksDS,
  jta.UserTransaction=UserTransaction,
  hibernate.show_sql=false,
  hibernate.transaction.factory_class=net.sf.hibernate.transaction.JTATransactionFactory}
[net.sf.hibernate.cfg.Environment] Hibernate 2.1 final
[net.sf.hibernate.cfg.Environment] hibernate.properties not found
[net.sf.hibernate.cfg.Environment] using CGLIB reflection optimizer

Lots of:

[net.sf.hibernate.cfg.Configuration] Mapping resource: com/galenworks/procedurelink/hibernate/UserDistribution.hbm.xml
[net.sf.hibernate.cfg.Binder] Mapping class: com.galenworks.procedurelink.hibernate.UserDistribution -> UserDistribution

[net.sf.hibernate.cfg.Binder] Mapping collection: com.galenworks.jetspeed.hibernate.User.roles -> turbine_user_group_role

[net.sf.hibernate.cfg.Configuration] processing one-to-many association mappings

Lots of:

[net.sf.hibernate.cfg.Binder] Mapping collection: com.galenworks.jetspeed.hibernate.User.activeAlerts -> UserDistribution

[net.sf.hibernate.cfg.Configuration] processing one-to-one association property references
[net.sf.hibernate.cfg.Configuration] processing foreign key constraints
[net.sf.hibernate.dialect.Dialect] Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
[net.sf.hibernate.cfg.SettingsFactory] Use outer join fetching: true
[net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
[net.sf.hibernate.connection.DatasourceConnectionProvider] Using datasource: java:/galenworksDS
[net.sf.hibernate.transaction.TransactionFactoryFactory] Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
[net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
[net.sf.hibernate.transaction.TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
[net.sf.hibernate.transaction.TransactionManagerLookupFactory] instantiated TransactionManagerLookup
[net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
[net.sf.hibernate.transaction.TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
[net.sf.hibernate.transaction.TransactionManagerLookupFactory] instantiated TransactionManagerLookup
[net.sf.hibernate.cfg.SettingsFactory] Use scrollable result sets: true
[net.sf.hibernate.cfg.SettingsFactory] JDBC 2 max batch size: 15
[net.sf.hibernate.cfg.SettingsFactory] Query language substitutions: {}
[net.sf.hibernate.cfg.SettingsFactory] cache provider: net.sf.ehcache.hibernate.Provider
[net.sf.hibernate.cfg.Configuration] instantiating and configuring caches
[net.sf.hibernate.impl.SessionFactoryImpl] building session factory

This next line is  OK:

[net.sf.hibernate.util.ReflectHelper] reflection optimizer disabled for: com.galenworks.procedurelink.hibernate.Document, NullPointerException: null

[net.sf.hibernate.impl.SessionFactoryObjectFactory] Factory name: java:/GWHibernateFactory
[net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
[net.sf.hibernate.impl.SessionFactoryObjectFactory] Bound factory to JNDI name: java:/GWHibernateFactory
[net.sf.hibernate.impl.SessionFactoryObjectFactory] InitialContext did not implement EventContext
[net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 2:50 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
I'm running JBoss from within Eclipse. My server.log doesn't have any information relating to hibernate.
I suspect my jboss-service.xml isn't loading the mbean. Is there something other than having a jboss-service.xml file with the mbean entry ( located in the META-INF directory ) needed to get the mbean to load ?

thanks,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 3:35 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
If there are no messages in the JBoss console, it looks like the Hibernate MBean is not deploying.

You have to package it into a SAR and put the SAR into the JBoss deploy directory. This is the case whether you are running inside or outside of Eclipse.

Having the jboss-service.xml in the SAR meta-inf directory is correct.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 4:44 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
thanks you for your help and patience. Im getting much different results now. Hibernate is getting loaded, but now my EJB is not. I will do some research as Im sure there is something else I need to do to get my EJB deployed

thanks,
Adam


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