-->
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: Can I use Hibernate in CMT? Any changes required?
PostPosted: Mon Jun 14, 2010 7:44 am 
Newbie

Joined: Mon Jun 14, 2010 7:37 am
Posts: 7
Hi All,

I am new to hibernate. We have a scenario like this.

In my application we are not using Hibernate. But there is a scenario where for the new feature we are adding hibernate.

In CMT we are calling a method which will do some db opertions using hibernate. But the results are not persisting in the db. it is throwing exceptions.

skelton:
CustomService(CMT) {
PartyRole (CMT) -> THIS IS NORMAL JXP (JDBC CALL)
Hibernate -> THIS IS A HIBERNATE CALL
}

sample code here:

public void find(){
/* some code here */
Retval = commonObjectBOB.create(username, authentication, theBO); -> db call..
String partyRoleID=retval.getId();
testPartyHib(partyRoleID); -> hibernate call..
}

public void testPartyHib(String id) throws Exception {
Session session = null;
try{
Configuration cfg = new Configuration();
SessionFactory sessionFactory=(SessionFactory) cfg.configure(CONFIG_FILE_LOCATION).buildSessionFactory();
session = sessionFactory.openSession();
// session.beginTransaction();
TestPartyHib testPartyHib = new TestPartyHib();
testPartyHib.setId(1L);
testPartyHib.setPartyRoleId(id);
session.save(testPartyHib);
session.flush();
//session.getTransaction().commit();
}
catch (SQLGrammarException ex) {
throw (SQLGrammarException) ex;
} finally{
session.close();
}
}
I am getting below error:
[6/14/10 14:52:17:962 EDT] 00000013 SystemOut O Hibernate: insert into TESTPARTYHIB (PARTYROLEID, id) values (?, ?)
[6/14/10 14:53:18:229 EDT] 00000013 SystemOut O 2010-06-14 14:53:18,219 [ORB.thread.pool : 2] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-02049: timeout: distributed transaction waiting for lock

[6/14/10 14:53:18:229 EDT] 00000013 SystemOut O 2010-06-14 14:53:18,229 [ORB.thread.pool : 2] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-02049: timeout: distributed transaction waiting for lock

[6/14/10 14:53:18:349 EDT] 00000013 SystemOut O 2010-06-14 14:53:18,259 [ORB.thread.pool : 2] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at com.chordiant.pmf.service.PartyRoleService.testPartyHib(PartyRoleService.java:298)
at com.chordiant.pmf.service.PartyRoleService.create(PartyRoleService.java:257)
at com.chordiant.pmf.service.PartyRoleService.processRequest(PartyRoleService.java:1809)
at com.chordiant.service.MasterStatelessServiceBean.processRequest(MasterStatelessServiceBean.java:527)
at com.chordiant.service.GatewayHandler.processRequest(GatewayHandler.java:266)
at com.chordiant.service.ejb.EJBGatewayServiceBean.processRequestObject(EJBGatewayServiceBean.java:172)
at com.chordiant.service.ejb.EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805.processRequestObject(EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805.java:28)
at com.chordiant.service.ejb._EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.processRequestObject(_EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.java:197)
at com.chordiant.service.ejb._EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie._invoke(_EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.java:106)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:613)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:466)
at com.ibm.rmi.iiop.ORB.process(ORB.java:503)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1552)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2673)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2551)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:62)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by:
java.sql.BatchUpdateException: ORA-02049: timeout: distributed transaction waiting for lock

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecuteBatch(WSJdbcPreparedStatement.java:808)
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeBatch(WSJdbcStatement.java:612)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 23 more
[6/14/10 14:53:18:349 EDT] 00000013 SystemOut O Exception visu java.sql.SQLException: ORA-02049: timeout: distributed transaction waiting for lock

[6/14/10 14:53:18:409 EDT] 00000013 SystemOut O <Mon Jun 14 14:53:18 EDT 2010> <1276541598409> <ERROR> <Thd=ORB.thread.pool : 2> <com.chordiant.pmf.service.PartyRoleService.create()> <Exception occured <org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update> >
[6/14/10 14:53:18:409 EDT] 00000013 SystemOut O <Mon Jun 14 14:53:18 EDT 2010> <1276541598409> <ERROR> <Thd=ORB.thread.pool : 2> <com.chordiant.pmf.service.PartyRoleService.processRequest()> <Exception occured <org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update> >
[6/14/10 14:53:18:419 EDT] 00000013 ExceptionUtil E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "processRequestObject" on bean "BeanId(ChordiantEAR#ChordiantEJB.jar#EJBGatewayServiceCMT, null)". Exception data: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at com.chordiant.pmf.service.PartyRoleService.testPartyHib(PartyRoleService.java:298)
at com.chordiant.pmf.service.PartyRoleService.create(PartyRoleService.java:257)
at com.chordiant.pmf.service.PartyRoleService.processRequest(PartyRoleService.java:1809)
at com.chordiant.service.MasterStatelessServiceBean.processRequest(MasterStatelessServiceBean.java:527)
at com.chordiant.service.GatewayHandler.processRequest(GatewayHandler.java:266)
at com.chordiant.service.ejb.EJBGatewayServiceBean.processRequestObject(EJBGatewayServiceBean.java:172)
at com.chordiant.service.ejb.EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805.processRequestObject(EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805.java:28)
at com.chordiant.service.ejb._EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.processRequestObject(_EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.java:197)
at com.chordiant.service.ejb._EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie._invoke(_EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.java:106)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:613)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:466)
at com.ibm.rmi.iiop.ORB.process(ORB.java:503)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1552)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2673)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2551)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:62)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: java.sql.BatchUpdateException: ORA-02049: timeout: distributed transaction waiting for lock

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecuteBatch(WSJdbcPreparedStatement.java:808)
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeBatch(WSJdbcStatement.java:612)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 23 more
---- Begin backtrace for Nested Throwables
java.sql.SQLException: ORA-02049: timeout: distributed transaction waiting for lock

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10580)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecuteBatch(WSJdbcPreparedStatement.java:808)
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeBatch(WSJdbcStatement.java:612)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at com.chordiant.pmf.service.PartyRoleService.testPartyHib(PartyRoleService.java:298)
at com.chordiant.pmf.service.PartyRoleService.create(PartyRoleService.java:257)
at com.chordiant.pmf.service.PartyRoleService.processRequest(PartyRoleService.java:1809)
at com.chordiant.service.MasterStatelessServiceBean.processRequest(MasterStatelessServiceBean.java:527)
at com.chordiant.service.GatewayHandler.processRequest(GatewayHandler.java:266)
at com.chordiant.service.ejb.EJBGatewayServiceBean.processRequestObject(EJBGatewayServiceBean.java:172)
at com.chordiant.service.ejb.EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805.processRequestObject(EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805.java:28)
at com.chordiant.service.ejb._EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.processRequestObject(_EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.java:197)
at com.chordiant.service.ejb._EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie._invoke(_EJSRemoteStatelessEJBGatewayServiceCMT_47cd5805_Tie.java:106)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:613)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:466)
at com.ibm.rmi.iiop.ORB.process(ORB.java:503)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1552)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2673)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2551)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:62)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)


Queries:
1. Can I use hibernate in CMT? If Yes, any configuration required?
2. Is it any dependency on ejb transaction attribute? I have tried with required, requiresNew. but did not work.


Please help me to resolve this problem.

-Kiran


Top
 Profile  
 
 Post subject: Re: Can I use Hibernate in CMT? Any changes required?
PostPosted: Wed Jun 23, 2010 5:56 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
sure you can, hibernate is actually used as EntityManager implementation for EJB3 compliance in several application servers.
It needs some configuration, mostly to be linked to the transactionmanager of the container; the reference documentation is listing exactly what you need to set, please read the manual for all details and it also shows a table with proper values to set for most popular application servers.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Can I use Hibernate in CMT? Any changes required?
PostPosted: Tue Jun 29, 2010 3:31 am 
Newbie

Joined: Mon Jun 14, 2010 7:37 am
Posts: 7
Finally I got the answer for this problem.

We need to pass the data base connection object to the hibernate session. That means both CMT and hibernate should use the same connection object.

we have a method in SessionFactory.OpenSession(Connection conn)

it will make use of the existing connection, here we no need to use any transaction object again.

-Kiran


Top
 Profile  
 
 Post subject: Re: Can I use Hibernate in CMT? Any changes required?
PostPosted: Tue Jun 29, 2010 3:44 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
we have a method in SessionFactory.OpenSession(Connection conn)

you shouldn't need to use that; have hibernate use the datasource from your container directly!

_________________
Sanne
http://in.relation.to/


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.