Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to start a transaction from client side in CMT

 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made small program in EJB2.0(Stateful SB and it's CMT ) and it's working fine and transaction attribute is "Required" for the bussinees method. But when i make this transaction attribute "Mandatory" i get the following error :-

Exception message CORBA TRANSACTION_REQUIRED 9998 Maybe

...Now i am thinking what i do that client can start transaction.I am using Sun J2EE server(1.3)..i have checked all the setting,not able to find any option,where client can start transaction ? How client will start transaction ?

Regards,

James
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NOW, I have done some R & D and when i call METHOD B() (Tx attribute Mandatory) from Method A() (Tx attribute Required).

Method A(tx attribute Required) calls Method B (tx attribute Mandatory)

It worked...but now the question is if i call Method B directly from JSP or Servlet it throws error.

So is client here means EJB only ? or we can JSP or servlet as a client too when we talk of transactions attributes

Regards,

James
[ June 03, 2004: Message edited by: james edwin ]
 
v Gupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mandatory transaction required means, the method for which this attribute has been defined must be called from a transaction and that transaction should have been started from EJB, not from Servlet or JSP
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The client must be in a transaction, that is why you are getting an exception.

For a client outside the EJB container, you need a UserTransaction in order to start a transaction. I don't know how it works in other containers, but for WebLogic the client uses JNDI to obtain a reference to the UserTransaction object for the WebLogic Server domain. Once this reference is obtained, and cast to UserTransaction, then you invoke its begin() method to start the transaction. The EJB can then be invoked and it will run in the client transaction.
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roger,

Thanks for explaination.But just need one clarification,how can we use JNDI to get reference to UserTransaction ?What all values we put ?

Regards,

James
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The values depend on your system, but here's an example.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic