-->
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: newbie: Insert exception...JTA Commit failed
PostPosted: Mon Jul 04, 2005 10:37 am 
Newbie

Joined: Mon Jun 20, 2005 11:18 am
Posts: 6
JBoss 4.0.2 & Hibernate 3.0 & MySQL 5.0

I am new to Hibernate. I am trying to create the "Cat" persistence example of Hibernate. The Cat table exists. I have deployed the EAR file. I wrote a simple servlet as follows:

Code:
public class HibernateExampleServlet extends HttpServlet {

    protected void service(HttpServletRequest request, HttpServletResponse response)      
    throws ServletException, IOException   
{      
//    ServletOutputStream out = response.getOutputStream();      
//    out.println("<html><body><h1>Hello World!</h1></body></html>");   
       
        Session session = HibernateUtil.currentSession();
        Transaction tx = session.beginTransaction();
        Cat princess = new Cat();
        princess.setName("Princess");
        princess.setSex('F');
        princess.setWeight(7.4f);
        session.save(princess);
        tx.commit();
        HibernateUtil.closeSession();
       
}

}


I get a "JTA Commit failed" exception caused by a NullPointerException as follows:


Code:
09:57:19,720 ERROR [JTATransaction] JTA commit failed
org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=PADYLAPTOP/14, BranchQual=, localId=14] statu
s=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.NullPointerException)
        at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:344)
        at org.jboss.tm.TxManager.commit(TxManager.java:200)
        at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:126)
        at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:130)
        at com.selfstudy.hibernate.example1.HibernateExampleServlet.service(HibernateExampleServlet.java:39)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:147)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:53)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:743)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.NullPointerException
        at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:1845)
        at com.mysql.jdbc.PreparedStatement.toString(PreparedStatement.java:1770)
        at java.lang.String.valueOf(String.java:2131)
        at java.lang.StringBuffer.append(StringBuffer.java:370)
        at com.mysql.jdbc.trace.Tracer.printParameters(Tracer.aj:240)
        at com.mysql.jdbc.trace.Tracer.printEntering(Tracer.aj:167)
        at com.mysql.jdbc.trace.Tracer.entry(Tracer.aj:126)
        at com.mysql.jdbc.trace.Tracer.ajc$before$com_mysql_jdbc_trace_Tracer$1$f51c62b8(Tracer.aj:45)
        at com.mysql.jdbc.Connection.registerStatement(Connection.java)
        at com.mysql.jdbc.Statement.<init>(Statement.java:171)
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:139)
        at com.mysql.jdbc.ServerPreparedStatement.toString(ServerPreparedStatement.java:851)
        at java.lang.String.valueOf(String.java:2131)
        at java.lang.StringBuffer.append(StringBuffer.java:370)
        at com.mysql.jdbc.trace.Tracer.printParameters(Tracer.aj:240)
        at com.mysql.jdbc.trace.Tracer.printEntering(Tracer.aj:167)
        at com.mysql.jdbc.trace.Tracer.entry(Tracer.aj:126)
        at com.mysql.jdbc.trace.Tracer.ajc$before$com_mysql_jdbc_trace_Tracer$1$f51c62b8(Tracer.aj:45)
        at com.mysql.jdbc.Connection.registerStatement(Connection.java)
        at com.mysql.jdbc.Statement.<init>(Statement.java:171)
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:201)
        at com.mysql.jdbc.ServerPreparedStatement.<init>(ServerPreparedStatement.java:133)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1370)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1335)
        at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:355)
        at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:205)
        at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:383)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:74)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:67)
        at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:148)
        at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1829)
        at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2190)
        at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:680)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309)
        at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:58)
        at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1384)
        at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1076)
        at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:296)
        ... 24 more



Here is some info from the system out during deployment:

Code:
09:56:28,326 INFO  [EARDeployer] Init J2EE application: file:/C:/javasoftware/jboss-4.0.2RC1/server/default/deploy/HibernateExample.ear
09:56:36,678 INFO  [Environment] Hibernate 3.0.2
09:56:36,698 INFO  [Environment] hibernate.properties not found
09:56:36,698 INFO  [Environment] using CGLIB reflection optimizer
09:56:36,698 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
09:56:36,938 INFO  [Hibernate] Using JDBC batch size : null
09:56:36,948 INFO  [Configuration] Searching for mapping documents in jar: HibernateExample.har
09:56:36,958 INFO  [Configuration] Found mapping documents in jar: Cat.hbm.xml
09:56:38,220 INFO  [HbmBinder] Mapping class: com.selfstudy.hibernate.example1.Cat -> CAT
09:56:38,450 INFO  [Configuration] processing extends queue
09:56:38,450 INFO  [Configuration] processing collection mappings
09:56:38,450 INFO  [Configuration] processing association property references
09:56:38,450 INFO  [Configuration] processing foreign key constraints
09:56:38,691 INFO  [NamingHelper] JNDI InitialContext properties:{}
09:56:38,701 INFO  [DatasourceConnectionProvider] Using datasource: java:/MySqlDS
09:56:38,861 INFO  [STDOUT] Mon Jul 04 09:56:38 EDT 2005 TRACE:  --> NonRegisteringDriver.java:223 com.mysql.jdbc.NonRegisteringDriver.acceptsURL("jdb
c:mysql://localhost:3306/jboss")
...
...
...
09:56:46,141 INFO  [SettingsFactory] RDBMS: MySQL, version: 5.0.6-beta-nt
09:56:46,141 INFO  [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.8 ( $Date: 2005/04/14 20:36:13 $, $Revision:
1.27.4.64 $ )
09:56:46,191 INFO  [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
09:56:46,201 INFO  [SettingsFactory] JDBC batch size: 15
09:56:46,201 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
09:56:46,201 INFO  [SettingsFactory] Scrollable result sets: enabled
09:56:46,201 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
09:56:46,201 INFO  [SettingsFactory] Aggressive release : disabled
09:56:46,201 INFO  [SettingsFactory] Maximum outer join fetch depth: 2
09:56:46,201 INFO  [SettingsFactory] Default batch fetch size: 1
09:56:46,201 INFO  [SettingsFactory] Generate SQL with comments: disabled
09:56:46,211 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
09:56:46,211 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
09:56:46,211 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
09:56:46,221 INFO  [SettingsFactory] Query language substitutions: {}
09:56:46,221 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
09:56:46,221 INFO  [NamingHelper] JNDI InitialContext properties:{}
09:56:46,231 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
09:56:46,231 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
09:56:46,231 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
09:56:46,231 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
09:56:46,231 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): enabled
09:56:46,231 INFO  [SettingsFactory] Automatic session close at end of transaction: enabled
09:56:46,231 INFO  [SettingsFactory] Second-level cache: enabled
09:56:46,231 INFO  [SettingsFactory] Query cache: disabled
09:56:46,231 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
09:56:46,242 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
09:56:46,242 INFO  [SettingsFactory] Structured second-level cache entries: enabled
09:56:46,272 INFO  [SettingsFactory] Statistics: disabled
09:56:46,272 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
09:56:46,272 INFO  [SettingsFactory] Default entity-mode: pojo
09:56:46,552 INFO  [SessionFactoryImpl] building session factory
09:56:46,732 INFO  [STDOUT] Mon Jul 04 09:56:46 EDT 2005 TRACE:  --> Statement.java:1627 com.mysql.jdbc.Statement.finalize()
09:56:46,732 INFO  [STDOUT] Mon Jul 04 09:56:46 EDT 2005 TRACE:  <--  Statement.java:1627 com.mysql.jdbc.Statement.finalize(..) returning null
09:56:46,732 INFO  [STDOUT] Mon Jul 04 09:56:46 EDT 2005 TRACE:  --> ResultSet.java:7079 com.mysql.jdbc.ResultSet.finalize()
09:56:46,732 INFO  [STDOUT] Mon Jul 04 09:56:46 EDT 2005 TRACE:  <--  ResultSet.java:7079 com.mysql.jdbc.ResultSet.finalize(..) returning null
09:56:47,373 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
09:56:47,383 INFO  [NamingHelper] JNDI InitialContext properties:{}
09:56:47,383 INFO  [SessionFactoryImpl] Checking 0 named queries
09:56:47,383 INFO  [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/SessionFactory]
09:56:47,403 INFO  [TomcatDeployer] deploy, ctxPath=/he, warUrl=file:/C:/javasoftware/jboss-4.0.2RC1/server/default/tmp/deploy/tmp28415HibernateExampl
e.ear-contents/HibernateExample-exp.war/
09:56:48,855 INFO  [EARDeployer] Started J2EE application: file:/C:/javasoftware/jboss-4.0.2RC1/server/default/deploy/HibernateExample.ear




Any help is appreciated.


Thanks

-- pady[/code]


Top
 Profile  
 
 Post subject: show_sql is true but...
PostPosted: Mon Jul 04, 2005 10:40 am 
Newbie

Joined: Mon Jun 20, 2005 11:18 am
Posts: 6
Although I have a hibernate.cfg.xml file, I am not sure if it is used in a JBoss environment. I do have show_sql as true in this file. But I dont see any sql being printed.

Thanks

-- pady


Top
 Profile  
 
 Post subject: set show_sql...
PostPosted: Mon Jul 04, 2005 12:40 pm 
Newbie

Joined: Mon Jun 20, 2005 11:18 am
Posts: 6
I set show_sql...

Code:
INFO  [STDOUT] Hibernate: insert into CAT (NAME, sex, weight, CAT_ID) values (?, ?, ?, ?)


Thanks

-- pady


Top
 Profile  
 
 Post subject: Figured it out...
PostPosted: Mon Jul 04, 2005 4:28 pm 
Newbie

Joined: Mon Jun 20, 2005 11:18 am
Posts: 6
It turned out to be a MySQL driver issue with 3.1. I went back to 3.0 and it works fine.

Thanks

-- pady


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.