Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

auto commit within JTS transaction  RSS feed

 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need help from you guys....
I have one stateless session bean transaction type is container managed (CMP).
I am getting the Connection object with the code written below:



now i need to either set connection to autocommit(true) or i want to explicitly give connection.commit() statement. doing so i m getting an exception which is:

ExceptionUtil E CNTR0020E: Non-application exception occurred while processing method "executeCommand" on bean "BeanId(DefaultEAR#MOIEJB.jar#DataAccessManager, null)". Exception data: java.lang.IllegalStateException: Cannot enable auto commit within JTS transaction
at com.ibm.ejs.cm.pool.ConnectO.setAutoCommit(ConnectO.java:2590)
at com.ibm.ejs.cm.proxy.ConnectionProxy.setAutoCommit(ConnectionProxy.java:651)
at com.zak.moi.ejb.db2.dao.DataAccessManagerBean.executeCommand(DataAccessManagerBean.java:278)
at com.zak.moi.ejb.db2.dao.EJSRemoteStatelessDataAccessManager_779ee2c3.executeCommand(EJSRemoteStatelessDataAccessManager_779ee2c3.java:42)
at com.zak.moi.ejb.db2.dao._DataAccessManager_Stub.executeCommand(_DataAccessManager_Stub.java:307)
at com.zak.moi.ejb.db2.transaction.LoggerBean.updateTransactionStatus(LoggerBean.java:292)
at com.zak.moi.ejb.db2.transaction.EJSRemoteStatelessLogger_bef34805.updateTransactionStatus(EJSRemoteStatelessLogger_bef34805.java:43)
at com.zak.moi.ejb.db2.transaction._Logger_Stub.updateTransactionStatus(_Logger_Stub.java:390)
.......
.....


can any one help me how should i implement my code to set it autocommit true or how can i commit the insert or update statement?? i dont want it to this method as JTS
 
Jason Hunt
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. for slsb, there is no CMP this kind of thing

2. which method are you coding with, for slsb, you can only try to use JTS in the business method.


 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay then tell me what i should use??
do i have to use BMP?? now i m trying to use this
its a stateless session bean which is BMP type.

now i m trying to use javax.transaction.UserTransaction to
do the begin and commit... tell me will it work??
well i have not tested it.. busy in some other issues once
that is done, shall look into it
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys!!

Now i have created a Stateless session bean with the type of BMP.

my code is ...



when i run my program, it prints Statement created.... and stop executing... and after a while i get a exception saying server time out... can any one tell me what mistake i m doing

thanks in advance guys
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did your class compile? The executeUpdate() method needs an SQL String arg.
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
executeUpdate(statment)....
where statment = sql statement (update statement)
there is spelling mistake in word statment... hance it is a different
string then statement

more over i m calling this BMP stateless bean from a stateless CMP bean... please help me.. i need it badly

i m using IBM websphere studio to compile, deploy etc..
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tausif,


can any one help me how should i implement my code to set it autocommit true or how can i commit the insert or update statement?


You could achieve such behaviour with CMT Session Bean.

As far as I understand you want to separate insert / update logic from other logic in your biz method. In order to do it you could create a new biz method that only has insert / update logic. This method is to have RequiresNew transaction attribute. Then you call this method (through component interface) from your main biz method.




Hope it helps
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex
Thanks lot for your reply,
I followed the instructions given by you.

It workd fine only when i made my entire class as "RequiresNew"... but server stops/hang executing at statement.executeUpdate(SqlStmt) command if i m setting the "RequiresNew" at method level. is it because i m getting the connection and datasource from different method in same class??

the update/insert method and getConnection method is given below:



kindly tell me why i m not able to use the transNew at method level i.e. on processCommand() method

thanks in advance
Tausif

[ August 16, 2004: Message edited by: Tausif Khanooni ]
[ August 16, 2004: Message edited by: Tausif Khanooni ]
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tausif,

Hmmm, interesting....

If I understood you correctly, you're saying that

1. When you define all methods (i.e. methods declared in your component interface) to use RequiresNew transaction attribute in container-transaction tag processCommand( String) method completes successfully.
I suspect your ejb-jar.xml has the following:



2. When you only define processCommand( String) method to have RequiresNew trans attribute it never completes and hangs on executeUpdate( String) line.
I suspect your ejb-jar.xml has the following:



In order to debug I'd do the following (with your method set to RequiresNew while all other methods have Required):

1. Rather than executing an update statement do a simple sql select from the table that does not get updated


Does the method complete?

2. Do a simple sql select from the table that gets updated (select all records)


Does the method complete?

[ August 16, 2004: Message edited by: Alex Sharkoff ]
[ August 16, 2004: Message edited by: Alex Sharkoff ]
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,
Thnx for your reply dude...




help me please
thnx in advance

[ August 17, 2004: Message edited by: Tausif Khanooni ]
[ August 18, 2004: Message edited by: Tausif Khanooni ]
 
Stan Sokolov
Ranch Hand
Posts: 120
Hibernate IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Guys,
I could got the idea:
CMP/BMP these are entity beans subtypes.
Stateless bean can use the following type of transactions:

TX_REQUIREDMethods executed within a transaction. If client provides transaction, it is used; if not, new transaction generated. Commit at end of method. Default attribute set by WebSphere Studio.
Well-suited for EJB Sessions.

TX_MANDATORYClient of this EJB must create a transaction in which this method operates, otherwise an error.
Well-suited for EJB Entitys.

TX_REQUIRES_NEWMethods executed within a transaction. If client provides transaction, it is suspended. A new transaction is generated, regardless. Commit at end of method.

TX_SUPPORTSTransactions optional.

TX_NOT_SUPPORTEDTransactions not supported; if provided, ignored..

TX_BEAN_MANAGEDCode in the EJB responsible for explicit transaction control. Applicable in WebSphere to EJB Sessions only.

Use the last one if you want to commit transaction manually.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!