-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to make Hibernate utilize the datasource for Jboss?
PostPosted: Mon Aug 21, 2006 12:15 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi all,

I'm using hibernate 3.2.cr2, mysql5, jboss4.0.3SP1.

I would like to know if i want Hibernate to utilize the datasource of JBoss 4.0.3 for connection pooling, what are the files that I need to edit? When edit, what are the configuration that I need to specify in order to get it work?
Is it context.xml, hibernate.cfg.xml, jboss-web.xml, web.xml, mysql-ds.xml (in Jboss) only?

context.xml
Code:
  <Resource auth="Container" driverClassName="org.gjt.mm.mysql.Driver" logAbandoned="true" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/cis" password="password" removeAbandoned="true" removeAbandonedTimeout="60" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3309/test?autoReconnect=true" username="root"/>


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

<hibernate-configuration>

    <session-factory>
        <!-- MySQL5 - Using application server database source -->
        <property name="connection.datasource">java:jdbc/cis</property>
        <property name="session_factory_name">java:jdbc/cis</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <property name="max_fetch_depth">3</property>

        <mapping resource="my/com/snt/cis/model/dep/Department.hbm.xml"/>
        <mapping resource="my/com/snt/cis/model/sta/Staff.hbm.xml"/>
        <mapping resource="my/com/snt/cis/model/sta/StaffSkill.hbm.xml"/>
        <mapping resource="my/com/snt/cis/model/sta/StaffStatus.hbm.xml"/>
        <mapping resource="my/com/snt/cis/model/ski/Skill.hbm.xml"/>

    </session-factory>

</hibernate-configuration>




jboss-web.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
  <security-domain flushOnSessionInvalidation="false"/>
  <context-root>/cis</context-root>
  <resource-ref>
    <res-ref-name>jdbc/cis</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <jndi-name>java:jdbc/cis</jndi-name>
  </resource-ref>
</jboss-web>


web.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <filter>
        <filter-name>Hibernate Filter</filter-name>
        <filter-class>my.com.snt.cis.filter.HibernateFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Hibernate Filter</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
   <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>

<resource-ref>
   <res-ref-name>jdbc/cis</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>



mysql-ds.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: mysql-ds.xml,v 1.3.2.1 2004/12/01 11:46:00 schrouf Exp $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->

<datasources>
  <local-tx-datasource>
    <jndi-name>jdbc/cis</jndi-name>
    <connection-url>jdbc:mysql://localhost:3309/test</connection-url>
    <driver-class>org.gjt.mm.mysql.Driver</driver-class>
    <user-name>root</user-name>
    <password>password</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- sql to call when connection is created
    <new-connection-sql></new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool
    <check-valid-connection-sql></check-valid-connection-sql>
      -->

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>



Please advise.
Thank you.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 12:51 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Set hibernate up to use JTA. There as some old docs in http://www.hibernate.org/66.html, though you'll have to update references to "net.sf.hibernate" to read "org.hibernate".

There are links from that page to presumably more up-to-date pages.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 2:37 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

Is it necessary to setup to use JTA?

Below is the output i get from my Jboss 4.0.3SP1 based on the original configuration which I posted to forum just now.

Hope to get some help.


Code:
===============================================================================
.
  JBoss Bootstrap Environment
.
  JBOSS_HOME: C:\Server\jboss-4.0.3SP1\bin\\..
.
  JAVA: C:\jdk1.5.0_03\bin\java
.
  JAVA_OPTS:  -Dprogram.name=run.bat -Xms128m -Xmx512m
.
  CLASSPATH: C:\jdk1.5.0_03\lib\tools.jar;C:\Server\jboss-4.0.3SP1\bin\\run.jar
.
===============================================================================
.
12:54:47,680 INFO  [Server] Starting JBoss (MX MicroKernel)...
12:54:47,696 INFO  [Server] Release ID: JBoss [Zion] 4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)
12:54:47,696 INFO  [Server] Home Dir: C:\Server\jboss-4.0.3SP1
12:54:47,696 INFO  [Server] Home URL: file:/C:/Server/jboss-4.0.3SP1/
12:54:47,696 INFO  [Server] Patch URL: null
12:54:47,696 INFO  [Server] Server Name: default
12:54:47,696 INFO  [Server] Server Home Dir: C:\Server\jboss-4.0.3SP1\server\default
12:54:47,696 INFO  [Server] Server Home URL: file:/C:/Server/jboss-4.0.3SP1/server/default/
12:54:48,180 INFO  [Server] Server Temp Dir: C:\Server\jboss-4.0.3SP1\server\default\tmp
12:54:48,180 INFO  [Server] Root Deployment Filename: jboss-service.xml
12:54:48,696 INFO  [ServerInfo] Java version: 1.5.0_03,Sun Microsystems Inc.
12:54:48,696 INFO  [ServerInfo] Java VM: Java HotSpot(TM) Client VM 1.5.0_03-b07,Sun Microsystems Inc.
12:54:48,696 INFO  [ServerInfo] OS-System: Windows XP 5.1,x86
12:54:49,805 INFO  [Server] Core system initialized
12:54:52,336 INFO  [WebService] Using RMI server codebase: http://JAPBC:8083/
12:54:52,368 INFO  [Log4jService$URLWatchTimerTask] Configuring from URL: resource:log4j.xml
12:54:53,305 INFO  [NamingService] Started jndi bootstrap jnpPort=1099, rmiPort=1098, backlog=50, bindAddress=/0.0.0.0, Client SocketFactory=null, Server SocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076
12:54:59,633 INFO  [Embedded] Catalina naming disabled
12:55:00,118 INFO  [Http11Protocol] Initializing Coyote HTTP/1.1 on http-0.0.0.0-8080
12:55:00,118 INFO  [Catalina] Initialization processed in 422 ms
12:55:00,118 INFO  [StandardService] Starting service jboss.web
12:55:00,118 INFO  [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.5
12:55:00,180 INFO  [StandardHost] XML validation disabled
12:55:00,211 INFO  [Catalina] Server startup in 93 ms
12:55:00,430 INFO  [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=.../deploy/http-invoker.sar/invoker.war/
12:55:01,102 INFO  [WebappLoader] Dual registration of jndi stream handler: factory already defined
12:55:01,665 INFO  [TomcatDeployer] deploy, ctxPath=/ws4ee, warUrl=.../tmp/deploy/tmp37550jboss-ws4ee-exp.war/
12:55:01,821 INFO  [TomcatDeployer] deploy, ctxPath=/, warUrl=.../deploy/jbossweb-tomcat55.sar/ROOT.war/
12:55:02,055 INFO  [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=.../deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/
12:55:04,649 INFO  [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=.../deploy/management/console-mgr.sar/web-console.war/
12:55:05,352 INFO  [MailService] Mail Service bound to java:/Mail
12:55:06,086 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-local-jdbc.rar
12:55:06,227 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-xa-jdbc.rar
12:55:06,368 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-local-jdbc.rar
12:55:06,508 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-xa-jdbc.rar
12:55:06,711 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jms/jms-ra.rar
12:55:06,868 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/mail-ra.rar
12:55:08,165 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'
12:55:08,493 INFO  [A] Bound to JNDI name: queue/A
12:55:08,508 INFO  [B] Bound to JNDI name: queue/B
12:55:08,508 INFO  [C] Bound to JNDI name: queue/C
12:55:08,508 INFO  [D] Bound to JNDI name: queue/D
12:55:08,508 INFO  [ex] Bound to JNDI name: queue/ex
12:55:08,524 INFO  [testTopic] Bound to JNDI name: topic/testTopic
12:55:08,524 INFO  [securedTopic] Bound to JNDI name: topic/securedTopic
12:55:08,524 INFO  [testDurableTopic] Bound to JNDI name: topic/testDurableTopic
12:55:08,540 INFO  [testQueue] Bound to JNDI name: queue/testQueue
12:55:08,758 INFO  [UILServerILService] JBossMQ UIL service available at : /0.0.0.0:8093
12:55:08,868 INFO  [DLQ] Bound to JNDI name: queue/DLQ
12:55:09,102 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
12:55:09,243 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/cis' to JNDI name 'java:jdbc/cis'
12:55:12,618 INFO  [TomcatDeployer] deploy, ctxPath=/aa, warUrl=.../tmp/deploy/tmp37605aa-exp.war/
12:55:13,008 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,008 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,008 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,024 WARN  [Digester] [ConverterRule]{faces-config/converter} Merge(null,mypackage.Location)
12:55:13,024 WARN  [Digester] [ManagedBeanRule]{faces-config/managed-bean} Merge(location)
12:55:13,024 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,196 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,196 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,196 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)
12:55:13,930 INFO  [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
12:55:16,665 INFO  [TomcatDeployer] deploy, ctxPath=/cis, warUrl=.../tmp/deploy/tmp37606train-exp.war/
12:55:16,868 INFO  [CIS] Servlet filter init, now opening/closing a Session for each request.
12:55:17,086 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
12:55:17,211 INFO  [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
12:55:17,227 INFO  [JkMain] Jk running ID=0 time=0/47  config=null
12:55:17,243 INFO  [Server] JBoss (MX MicroKernel) [4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)] Started in 29s:63ms
12:55:21,899 INFO  [TomcatDeployer] undeploy, ctxPath=/cis, warUrl=.../tmp/deploy/tmp37606train-exp.war/
12:55:24,571 INFO  [TomcatDeployer] deploy, ctxPath=/cis, warUrl=.../tmp/deploy/tmp37607train-exp.war/
12:55:24,665 INFO  [CIS] Servlet filter init, now opening/closing a Session for each request.
12:55:24,790 INFO  [Environment] Hibernate 3.2 cr2
12:55:24,790 INFO  [Environment] hibernate.properties not found
12:55:24,805 INFO  [Environment] Bytecode provider name : cglib
12:55:24,805 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
12:55:24,946 INFO  [Configuration] configuring from resource: /hibernate.cfg.xml
12:55:24,946 INFO  [Configuration] Configuration resource: /hibernate.cfg.xml
12:55:25,040 INFO  [Configuration] Reading mappings from resource: my/com/snt/cis/model/dep/Department.hbm.xml
12:55:25,805 INFO  [HbmBinder] Mapping class: my.com.snt.cis.model.dep.Department -> t_department
12:55:25,836 INFO  [Configuration] Reading mappings from resource: my/com/snt/cis/model/sta/Staff.hbm.xml
12:55:25,868 INFO  [HbmBinder] Mapping class: my.com.snt.cis.model.sta.Staff -> t_staff
12:55:25,977 INFO  [Configuration] Reading mappings from resource: my/com/snt/cis/model/sta/StaffSkill.hbm.xml
12:55:25,977 INFO  [HbmBinder] Mapping class: my.com.snt.cis.model.sta.StaffSkill -> t_staff_skill
12:55:25,993 INFO  [Configuration] Reading mappings from resource: my/com/snt/cis/model/sta/StaffStatus.hbm.xml
12:55:29,211 INFO  [HbmBinder] Mapping class: my.com.snt.cis.model.sta.StaffStatus -> t_staff_status
12:55:29,211 INFO  [Configuration] Reading mappings from resource: my/com/snt/cis/model/ski/Skill.hbm.xml
12:55:29,211 INFO  [HbmBinder] Mapping class: my.com.snt.cis.model.ski.Skill -> t_skill
12:55:29,227 INFO  [Configuration] Configured SessionFactory: null
12:55:29,227 INFO  [HbmBinder] Mapping collection: my.com.snt.cis.model.dep.Department.staffs -> t_staff
12:55:32,196 INFO  [HbmBinder] Mapping collection: my.com.snt.cis.model.sta.Staff.staffSkills -> t_staff_skill
12:55:32,196 INFO  [HbmBinder] Mapping collection: my.com.snt.cis.model.ski.Skill.staffSkills -> t_staff_skill
12:55:32,290 INFO  [NamingHelper] JNDI InitialContext properties:{}
12:55:32,290 INFO  [DatasourceConnectionProvider] Using datasource: java:jdbc/cis
12:55:32,555 INFO  [SettingsFactory] RDBMS: MySQL, version: 5.0.15-nt
12:55:32,555 INFO  [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.16-ga ( $Date: 2004/09/30 07:35:03 $, $Revision: 1.27.2.44 $ )
12:55:35,227 INFO  [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
12:55:35,227 INFO  [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
12:55:35,227 INFO  [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:55:35,227 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
12:55:35,227 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
12:55:38,540 INFO  [SettingsFactory] JDBC batch size: 15
12:55:38,540 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
12:55:38,555 INFO  [SettingsFactory] Scrollable result sets: enabled
12:55:38,555 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
12:55:38,555 INFO  [SettingsFactory] Connection release mode: auto
12:55:38,571 INFO  [SettingsFactory] Maximum outer join fetch depth: 3
12:55:38,571 INFO  [SettingsFactory] Default batch fetch size: 1
12:55:38,571 INFO  [SettingsFactory] Generate SQL with comments: disabled
12:55:41,040 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
12:55:41,040 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:55:41,040 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
12:55:41,040 INFO  [SettingsFactory] Query language substitutions: {}
12:55:41,040 INFO  [SettingsFactory] Second-level cache: enabled
12:55:41,040 INFO  [SettingsFactory] Query cache: disabled
12:55:41,040 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.NoCacheProvider
12:55:45,040 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
12:55:45,040 INFO  [SettingsFactory] Structured second-level cache entries: disabled
12:55:45,040 INFO  [SettingsFactory] Echoing all SQL to stdout
12:55:45,040 INFO  [SettingsFactory] Statistics: disabled
12:55:45,040 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
12:55:45,040 INFO  [SettingsFactory] Default entity-mode: pojo
12:55:45,102 INFO  [SessionFactoryImpl] building session factory
12:55:45,915 INFO  [SessionFactoryObjectFactory] Factory name: java:jdbc/cis
12:55:48,540 INFO  [NamingHelper] JNDI InitialContext properties:{}
12:55:48,540 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: java:jdbc/cis
12:55:48,540 WARN  [SessionFactoryObjectFactory] InitialContext did not implement EventContext
12:57:17,430 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
12:57:17,430 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
12:57:17,430 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
12:57:17,430 ERROR [JDBCExceptionReporter] No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
12:57:17,430 ERROR [JDBCExceptionReporter] No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
12:57:17,430 ERROR [JDBCExceptionReporter] No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
12:57:31,930 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
my.com.snt.cis.exception.InfrastructureException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:20        at my.com.snt.cis.filter.HibernateFilter.doFilter(HibernateFilter.java:2        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:8        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:21        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:17        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:3        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:5        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:12        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:10        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:14        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:74        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:11        at java.lang.Thread.run(Thread.java:59Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:10        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:9        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:4        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:2        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:42        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:14        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:11        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:5        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:131        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:19        ... 20 moCaused by: org.jboss.util.NestedSQLException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
        at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:7        at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:6        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:41        ... 25 moCaused by: javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] )
        at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:24        at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:52        at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:41        at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:34        at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:46        at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:89        at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:7        ... 27 mo12:57:31,930 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
my.com.snt.cis.exception.InfrastructureException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:20        at my.com.snt.cis.filter.HibernateFilter.doFilter(HibernateFilter.java:2        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:8        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:21        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:17        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:3        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:5        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:12        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:10        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:14        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:74        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:11        at java.lang.Thread.run(Thread.java:59Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:10        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:9        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:4        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:2        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:42        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:14        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:11        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:5        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:131        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:19        ... 20 moCaused by: org.jboss.util.NestedSQLException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
        at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:7        at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:6        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:41        ... 25 moCaused by: javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] )
        at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:24        at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:52        at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:41        at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:34        at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:46        at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:89        at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:7        ... 27 mo12:57:31,930 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
my.com.snt.cis.exception.InfrastructureException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:20        at my.com.snt.cis.filter.HibernateFilter.doFilter(HibernateFilter.java:2        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:8        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:21        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:17        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:3        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:5        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:12        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:10        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:14        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:74        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:11        at java.lang.Thread.run(Thread.java:59Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:10        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:9        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:4        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:2        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:42        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:14        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:11        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:5        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:131        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:19        ... 20 moCaused by: org.jboss.util.NestedSQLException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
        at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:7        at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:6        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:41        ... 25 moCaused by: javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] )
        at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:24 

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 5:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Well, you've got to do something to get some connections. You don't have to use JTA, you can use JDBC transactions, but JTA is probably the most widely used standard in this area, and JBoss comes with a JTA implementation.

Chapter 3 of the ref docs have all the info. hibernate.cfg.xml is the place to start, I think.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 6:58 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

Sorry I'm not so clear in this.

Do you mean with all the configuration that I specify currently (eg. eventhough I have bind session_factory_name to java:jdbc/cis and specify the data source to be java:jdbc/cis and defined connection profile in mysql-ds.xml) my application is still not getting connection? May I know why you say so?

This is my first time trying to get my hibernate application run in jboss (i manage to get it run in tomcat), can you provide more specific instruction on which command or statement should I add to my current configuration so that I can tryout faster? I did read chapter 3 before this but to me it's still too broad for me to put the what is needed and put it right to my application.

So, hope you can provide more specific details, like what to add if i use jdbc transaction and what to add if i use JTA. Really appreciate your help. :)

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 9:18 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The exception you posted says that there was a timeout connecting to your server, so something is misconfigured. Getting a DB connection should take no more than a few dozen milliseconds, but yours is timing out after 30,000 millisecnods.

I suppose that you should try connecting to your DB via the client it provides. It is possible that the problem is something trivial like a bad port number.

Your .cfg.xml file looks close to right, but there's no transaction manager or transaction factory specified. I think that these are the lines you need:
Code:
hibernate.transaction.factory_class = org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = org.hibernate.transaction.JBossTransactionManagerLookup
Use JDBCTransactionFactory instead of JTATransactionFactory to use plain old transactions. The JBossTransactionManager handles both, I think, so no need to change that. If you do want the plain-old variety, it's just TransactionManagerLookup.

BTW you are using the old property names in your .cfg.xml file. Hibernate converts them internally for the moment, so they work, but you should change them so that they will continue to work in future versions. All properties now begin with "hibernate.".

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 11:52 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

I added the 2 config statements that you provide to me and below is the extracted output from jboss. But looks like now i have problem with the transaction manager? What else to configure/change?

Fyi, my flow of application is like this. All incoming jsp will go through a filter called HibernateFilter.
HibernateFilter will access HibernateUtil class to manage the begin and commit transaction and ensure hibernate session are closed when jsp is fully processed. I hereby include my HibernateFilter and HibernateUtil class for your advise if anything need to modify to work with the JTA that you teach me to add in just now.

Sorry for the lengthy posting.

===================
HibernateFilter Class
===================
Code:
package my.com.snt.cis.filter;

import javax.servlet.*;
import java.io.IOException;
import my.com.snt.cis.Application;
import my.com.snt.util.HibernateUtil;
import org.apache.commons.logging.*;

public class HibernateFilter implements Filter {

   private static Log log = LogFactory.getLog(Application.strAppLogName);

   public void init(FilterConfig filterConfig) throws ServletException {
      log.info("Servlet filter init, now opening/closing a Session for each request.");
   }

   public void doFilter(ServletRequest request, ServletResponse response,
                             FilterChain chain) throws IOException, ServletException {

      try {
                        HibernateUtil.beginTransaction();

                        System.out.println("[Transaction Begin]");
         chain.doFilter(request, response);

         // Commit any pending database transaction.
         HibernateUtil.commitTransaction();
                        System.out.println("[Transaction End]");
      } finally {
         // No matter what happens, close the Session.
         HibernateUtil.closeSession();
                        System.out.println("[Close Session]");
      }
   }

   public void destroy() {}

}



===================
HibernateUtil Class
===================
Code:
package my.com.snt.util;

import my.com.snt.cis.Application;
import my.com.snt.cis.exception.InfrastructureException;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.*;
import javax.naming.*;
import org.hibernate.cfg.Environment;

public class HibernateUtil {

   private static Log log = LogFactory.getLog(Application.strAppLogName);

   private static Configuration configuration;
   private static SessionFactory sessionFactory;
   private static final ThreadLocal threadSession = new ThreadLocal();
   private static final ThreadLocal threadTransaction = new ThreadLocal();
   private static final ThreadLocal threadInterceptor = new ThreadLocal();

   // Create the initial SessionFactory from the default configuration files
   static {
      try {
                        configuration = new Configuration();
                        configuration.configure();

         if (configuration.getProperty(Environment.SESSION_FACTORY_NAME) != null) {
             // Let Hibernate bind the factory to JNDI
             configuration.buildSessionFactory();
         } else {
             // or use static variable handling
             sessionFactory = configuration.buildSessionFactory();
         }

                } catch (Throwable ex) {
         log.error("Building SessionFactory failed.", ex);
                        System.out.println("HibernateUtil.java : " + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }

   /**
    * Returns the SessionFactory used for this static class.
    *
    * @return SessionFactory
    */
   public static SessionFactory getSessionFactory() {
      SessionFactory sf = null;
      String sfName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
      if ( sfName != null) {
          log.debug("Looking up SessionFactory in JNDI.");
          try {
         sf = (SessionFactory) new InitialContext().lookup(sfName);
          } catch (NamingException ex) {
         throw new RuntimeException(ex);
          }
      } else {
          sf = sessionFactory;
      }
      if (sf == null)
          throw new InfrastructureException("SessionFactory not available.");
      return sf;           
        }

   /**
    * Returns the original Hibernate configuration.
    *
    * @return Configuration
    */
   public static Configuration getConfiguration() {
      return configuration;
   }

   /**
    * Rebuild the SessionFactory with the static Configuration.
    *
    */
    public static void rebuildSessionFactory()
      throws InfrastructureException {
      synchronized(sessionFactory) {
         try {
            sessionFactory = getConfiguration().buildSessionFactory();
         } catch (Exception ex) {
            throw new InfrastructureException(ex);
         }
      }
    }

   /**
    * Rebuild the SessionFactory with the given Hibernate Configuration.
    *
    * @param cfg
    */
    public static void rebuildSessionFactory(Configuration cfg)
      throws InfrastructureException {
      synchronized(sessionFactory) {
         try {
            sessionFactory = cfg.buildSessionFactory();
            configuration = cfg;
         } catch (Exception ex) {
            throw new InfrastructureException(ex);
         }
      }
    }

   /**
    * Retrieves the current Session local to the thread.
    * <p/>
    * If no Session is open, opens a new Session for the running thread.
    *
    * @return Session
    */
   public static Session getSession()
      throws InfrastructureException {
      Session s = (Session) threadSession.get();
      try {
         if (s == null) {
            log.debug("Opening new Session for this thread.");
            if (getInterceptor() != null) {
               log.debug("Using interceptor: " + getInterceptor().getClass());
               s = getSessionFactory().openSession(getInterceptor());
            } else {
               s = getSessionFactory().openSession();
            }
            threadSession.set(s);
         }
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      }
      return s;
   }

   /**
    * Closes the Session local to the thread.
    */
   public static void closeSession()
      throws InfrastructureException {
      try {
         Session s = (Session) threadSession.get();
         threadSession.set(null);
         if (s != null && s.isOpen()) {
            log.debug("Closing Session of this thread.");
            s.close();
         }
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      }
   }

   /**
    * Start a new database transaction.
    */
   public static void beginTransaction()
      throws InfrastructureException {
      Transaction tx = (Transaction) threadTransaction.get();
      try {
         if (tx == null) {
            log.debug("Starting new database transaction in this thread.");
            tx = getSession().beginTransaction();
            threadTransaction.set(tx);
         }
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      }
   }

   /**
    * Commit the database transaction.
    */
   public static void commitTransaction()
      throws InfrastructureException {
      Transaction tx = (Transaction) threadTransaction.get();
      try {
         if ( tx != null && !tx.wasCommitted()
            && !tx.wasRolledBack() ) {
            log.debug("Committing database transaction of this thread.");
            tx.commit();
         }
         threadTransaction.set(null);
      } catch (HibernateException ex) {
         rollbackTransaction();
         throw new InfrastructureException(ex);
      }
   }

   /**
    * Commit the database transaction.
    */
   public static void rollbackTransaction()
      throws InfrastructureException {
      Transaction tx = (Transaction) threadTransaction.get();
      try {
         threadTransaction.set(null);
         if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
            log.debug("Trying to rollback database transaction of this thread.");
            tx.rollback();
         }
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      } finally {
         closeSession();
      }
   }

   /**
    * Reconnects a Hibernate Session to the current Thread.
    *
    * @param session The Hibernate Session to be reconnected.
    */
   public static void reconnect(Session session)
      throws InfrastructureException {
      try {
         session.reconnect();
         threadSession.set(session);
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      }
   }

   /**
    * Disconnect and return Session from current Thread.
    *
    * @return Session the disconnected Session
    */
   public static Session disconnectSession()
      throws InfrastructureException {

      Session session = getSession();
      try {
         threadSession.set(null);
         if (session.isConnected() && session.isOpen())
            session.disconnect();
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      }
      return session;
   }

   /**
    * Register a Hibernate interceptor with the current thread.
    * <p>
    * Every Session opened is opened with this interceptor after
    * registration. Has no effect if the current Session of the
    * thread is already open, effective on next close()/getSession().
    */
   public static void registerInterceptor(Interceptor interceptor) {
      threadInterceptor.set(interceptor);
   }

   private static Interceptor getInterceptor() {
      Interceptor interceptor =
         (Interceptor) threadInterceptor.get();
      return interceptor;
   }

}



===================
Partial Jboss Output
===================
Code:
11:34:09,557 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
11:34:12,416 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
11:34:12,416 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
11:34:12,416 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
...
...
...
11:34:22,291 INFO  [SessionFactoryImpl] building session factory
11:34:25,057 INFO  [SessionFactoryObjectFactory] Factory name: java:jdbc/cis
11:34:25,416 INFO  [NamingHelper] JNDI InitialContext properties:{}
11:34:25,416 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: java:jdbc/cis
11:34:25,416 WARN  [SessionFactoryObjectFactory] InitialContext did not implement EventContext
11:34:25,416 INFO  [NamingHelper] JNDI InitialContext properties:{}
11:34:25,416 ERROR [CIS] Building SessionFactory failed.
java.lang.ClassCastException: org.jboss.tm.TxManager
        at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:2        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:32        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:121        at my.com.snt.util.HibernateUtil.<clinit>(HibernateUtil.java:4        at my.com.snt.cis.filter.HibernateFilter.doFilter(HibernateFilter.java:2        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:8        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:21        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:17        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:3        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:5        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:12        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:10        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:14        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:74        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:11        at java.lang.Thread.run(Thread.java:5911:34:29,416 INFO  [STDOUT] HibernateUtil.java : java.lang.ClassCastException: org.jboss.tm.TxManager
11:34:29,416 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError
        at my.com.snt.cis.filter.HibernateFilter.doFilter(HibernateFilter.java:3        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:8        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:21        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:17        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:3        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:5        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:12        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:10        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:14        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:74        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:11        at java.lang.Thread.run(Thread.java:5911:34:29,416 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 1:18 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It's the transaction manager lookup factory that's complaining, not the transaction manager. Where have you set up JNDITransactionManagerLookup? I'm guessing that you've told one thing that you're using JNDITransactionManagerLookup, and another thing that you're using JBossTransactionManagerLookup. Have a look for all instances of both strings and figure out which one is the one you need. It's probably the JNDI one, but I can't be sure.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 1:41 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi Tenwit,
First of all, thanks for your continuous support.

What I show you in my previous posts are all what I have configured.

Most recent one I add the following to hibernate.cfg.xml file.
Code:
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

So, I don't really setup JNDITransactionManagerLookup anywhere.

Sorry, I'm really new to this, but Yes, I think JNDI is the one that I need.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 2:39 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi Tenwit,

If i don't include

Code:
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>


in the hibernate.cfg.xml file, then the error from jboss is:

Code:
14:26:57,003 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: org.jboss.tm.usertx.client.ServerVMClientUserTransaction
        at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:6        at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:5        at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:18        at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:130        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:131        at my.com.snt.util.HibernateUtil.beginTransaction(HibernateUtil.java:20        at my.com.snt.cis.filter.HibernateFilter.doFilter(HibernateFilter.java:2        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:8        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:20        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:17        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:21        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:17        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:3        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:5        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:12        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:10        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:14        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:74        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:11        at java.lang.Thread.run(Thread.java:5914:26:57,003 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception


Hope the info will be useful for you to advise me further.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 5:34 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I'm afraid that those exceptions are outside my area of (limited) expertise. Try changing the reference to JBossTransactionManagerLookup to JNDITransactionManagerLookup. After that, all I can think of is that you have a jar mismatch: I can't think of any other reason that a standard class like a transaction manager lookup factory would be causing a class cast exception. Unfortunately, I have no idea what versions of JNDI are compatible with the various JNDI files in hibernate: I'd have thought there'd be no problem..

If you make no progress, I suggest dropping JNDI entirely until you get hibernate+JBoss working, then converting the various connection properties to use JNDI afterwards.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 02, 2006 2:05 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

I have tried to drop JNDI entirely and my application can run without problem.

But I still can't get the JNDI thing working. I guess the best is to have a complete sample code which I can refer to tryout, instead of bit and pieces of snippet and guessing here and there.

I know there are many hibernate expert and hibernate own developer in this forum, besides Hibernate is from JBOss, I'm sure someone in this forum will be very familiar to get hibernate work with Jboss application server (jndi part) and be able to help me on getting the JNDI work.

Can someone advise further on this?

My current status is I'm getting the java.lang.ClassCastException: org.jboss.tm.usertx.client.ServerVMClientUserTransaction error whenever a query.list() is being executed.

Thanks in advance.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 10:40 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Dear Hibernate experts,

Can you please advise on the mentioned problem?

Why am I getting org.jboss.tm.usertx.client.ServerVMClientUserTransaction when trying to do a query.list() ?

Really appreciate your help.

Thank you.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 2:48 pm 
Newbie

Joined: Wed Sep 13, 2006 2:44 pm
Posts: 6
Location: San Diego, CA
Quick reply to an earlier comment. I found that this error:
Code:
java.lang.ClassCastException: org.jboss.tm.TxManager

was caused by accidental bundling of the javax.transaction.TransactionManager class in my ear. It got there via the jta-<version>.jar which was a transitive dependency of Hibernate when building using Maven.

Details: http://autoedification.blogspot.com/200 ... aven2.html

So perhaps you can try an earlier configuration, and make sure you've eliminated any container-provided classes from your ear/war.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 10:04 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi timmorrow,

Thanks for the advise.

Between, I manage to find hint to resolve my problem through Jboss forum, where i exclude jta.jar from my war project. At the same time, I replace hibernate3.jar in jboss 4.0.3Sp1 with the hibernate3.jar I have from my Hibernate 3.2cr2 libraries.

Anyway, thanks.

One thing I find out is now my application is without issuing session.flush(), my updates are not write to database. I read from documentation actually session.flush is not always issue so that Hibernate can achieve better performance, but in my case if i don't issue, the record is not updated and user seeing the wrong info and thought it's not updated.

Any good advice? Appreciate it.

Thanks.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.