-->
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.  [ 1 post ] 
Author Message
 Post subject: javax.ejb.EJBException: Unexpected Error
PostPosted: Thu Jul 07, 2005 7:08 am 
Newbie

Joined: Thu Jul 07, 2005 6:59 am
Posts: 13
Location: Derry Northern Ireland
Hi, I am new to Hibernate and Jboss so getting the architecture right here is a little confusing.

This is my problem,

I am getting an unexspected error thrown from my onMessage method in my message driven bean.

As the docs state this will happen for example if the instance failed to open a database connection.

This is what I am doing but through Hibernate.

My onMessage method is trying to open and close a session just at this point.

I'm using JBoss 3.2.5 with Hibernate 2.1.

This is my onMessage method


Code:
public void onMessage(Message message){
       
        try{
           
            ObjectMessage oMessage = (ObjectMessage)message;
            MyTestBean bean = (MyTestBean)oMessage.getObject();
            System.out.println("Received : "+bean.getMessage());
            message.acknowledge();
           
            System.out.println("Trying hiberante connection");
            HibernateSession.currentSession();
            System.out.println("Got Hibernate Session");
            HibernateSession.closeSession();
            System.out.println("Clossed Hibernate Session");

            //sendReply();
       
        }catch(Exception e){
            System.out.println("Error : "+e.getMessage());
        }
       
    }




this is my HibernateSession singleton class that will manage the sessions


Code:
package server.j2eeHibernate.components;

import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.HibernateException;

import javax.naming.Context;
import javax.naming.InitialContext;
       
public class HibernateSession {
   
    private static final SessionFactory sessionFactory;
   
    static{
       
        try{
           
           Context ctx = new InitialContext();
           sessionFactory = (SessionFactory)ctx.lookup("java:/HibernateFactory");
           
        }catch(Exception e){
           
            throw new RuntimeException("SessionFactory Error - " + e.getMessage(),e);
           
        }
       
    }
   
    public static final ThreadLocal session = new ThreadLocal();
   
    public static Session currentSession() throws HibernateException{
       
        Session s = (Session)session.get();
        if(s==null){
            s = sessionFactory.openSession();
            session.set(s);
        }
       
        return s;
       
    }
   
    public static void closeSession() throws HibernateException{
       
        Session s = (Session)session.get();
        session.set(null);
        if(s!=null){
            s.close();
        }
       
    }
   
}





These are my xml config files for Hibernate and Jboss to talk,


//jboss-service.xml
Code:
<server>
<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=asademo</depends>
    <!-- Make it deploy ONLY after DataSource had been started -->
    <attribute name="MapResources">server/j2eeHibernate/deploy/classes/versioning/VModule.hbm.xml</attribute>
    <attribute name="JndiName">java:/com/env/HibernateFactory</attribute>
    <attribute name="Datasource">java:/asademo</attribute>
    <attribute name="Dialect">net.sf.hibernate.dialect.SybaseAnywhereDialect</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">false</attribute>
    <attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>



//hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory>
        <property name="connection.driver">com.sybase.jdbc2.jdbc.SybDriver</property>
        <property name="connection.url">jdbc:sybase:Tds:localhost:2638?ServiceName=asademo</property>
        <property name="dialect">net.sf.hibernate.dialect.SybaseAnywhereDialect</property>
        <property name="connection.username">DBA</property>
        <property name="connection.password">SQL</property>

        <mapping resource="server\j2eeHibernate\deploy\classes\versioning\VModule.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


//and hibernatesybase-ds.xml
Code:
<datasources>
   <local-tx-datasource>
      <jndi-name>HibernateFactory</jndi-name>
      <connection-url>jdbc:sybase:Tds://localhost:2638/asademo</connection-url>
      <driver-class>com.sybase.jdbc2.jdbc.SybDriver</driver-class>
      <user-name>DBA</user-name>
      <password>SQL</password>
   </local-tx-datasource>
</datasources>




both jboss-service.xml and hibernate.cfg.xml reside in the root of my deployed jar file.

hibernatesybase-ds.xml is sitting in my jboss/server/default/deploy.

this is my stack trace,

11:28:44,635 INFO [STDOUT] Trying hiberante connection
11:28:44,651 ERROR [LogInterceptor] Unexpected Error:
java.lang.ExceptionInInitializerError
at server.j2eeHibernate.deploy.MyMessageBean.onMessage(MyMessageBean.jav
a:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(Mess
ageDrivenContainer.java:458)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
ke(CachedConnectionInterceptor.java:185)
at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(Message
DrivenInstanceInterceptor.java:62)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
rceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
torCMT.java:282)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
48)
at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityIn
terceptor.java:90)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
ryFinderInterceptor.java:122)
at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenCont
ainer.java:372)
at org.jboss.ejb.Container.invoke(Container.java:723)
at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvo
ker.java:914)
at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onM
essage(JMSContainerInvoker.java:1208)
at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:27
6)
at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMess
ageConsumer.java:871)
at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:15
9)
at org.jboss.mq.SpySession.run(SpySession.java:347)
at org.jboss.jms.asf.StdServerSession.run0(StdServerSession.java:200)
at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:180)
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
utor.java:743)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: SessionFactory Error - org.jboss.resource
.adapter.jdbc.WrapperDataSource
at server.j2eeHibernate.components.HibernateSession.<clinit>(HibernateSe
ssion.java:23)
... 26 more
Caused by: java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.Wrapper
DataSource
at server.j2eeHibernate.components.HibernateSession.<clinit>(HibernateSe
ssion.java:19)
... 26 more
11:28:44,651 ERROR [JMSContainerInvoker] Exception in JMSCI message listener
javax.ejb.EJBException: Unexpected Error
java.lang.ExceptionInInitializerError
at server.j2eeHibernate.deploy.MyMessageBean.onMessage(MyMessageBean.jav
a:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(Mess
ageDrivenContainer.java:458)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
ke(CachedConnectionInterceptor.java:185)
at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(Message
DrivenInstanceInterceptor.java:62)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
rceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
torCMT.java:282)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
48)
at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityIn
terceptor.java:90)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
ryFinderInterceptor.java:122)
at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenCont
ainer.java:372)
at org.jboss.ejb.Container.invoke(Container.java:723)
at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvo
ker.java:914)
at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onM
essage(JMSContainerInvoker.java:1208)
at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:27
6)
at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMess
ageConsumer.java:871)
at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:15
9)
at org.jboss.mq.SpySession.run(SpySession.java:347)
at org.jboss.jms.asf.StdServerSession.run0(StdServerSession.java:200)
at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:180)
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
utor.java:743)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: SessionFactory Error - org.jboss.resource
.adapter.jdbc.WrapperDataSource
at server.j2eeHibernate.components.HibernateSession.<clinit>(HibernateSe
ssion.java:23)
... 26 more
Caused by: java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.Wrapper
DataSource
at server.j2eeHibernate.components.HibernateSession.<clinit>(HibernateSe
ssion.java:19)
... 26 more

at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.j
ava:370)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
ryFinderInterceptor.java:122)
at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenCont
ainer.java:372)
at org.jboss.ejb.Container.invoke(Container.java:723)
at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvo
ker.java:914)
at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onM
essage(JMSContainerInvoker.java:1208)
at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:27
6)
at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMess
ageConsumer.java:871)
at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:15
9)
at org.jboss.mq.SpySession.run(SpySession.java:347)
at org.jboss.jms.asf.StdServerSession.run0(StdServerSession.java:200)
at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:180)
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
utor.java:743)
at java.lang.Thread.run(Thread.java:595)

Thanks for any help on this,

JP.

Code:
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.