• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

IllegalStateException

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using container managed transactions

A) in few methods i have transaction attribute as required
B) in few methods i have transaction attribute as supports

thus sometimes a method firing only select queris (methods in B) may be in transaction if called from A, or sometimes not in transaction if called directly

on getting any exception, i want to rollback transaction

using SessionContext.getUserTransaction() gives illegal state exception

sessionContext.setRollBackOnly() gives illegal state exception

the j2ee docs says that for container managed transcations THESE METHODS CANNOT BE CALLED

now, the question is how do i know in my ejb code whether current code is running under transactions or not !



Kalpesh Soni
[ July 28, 2007: Message edited by: Kalpesh Soni ]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First: where do you try to rollback the transaction, in the calling methods (TX_REQUIRED) or the failing query-methods (TX_SUPPORTS)?
In the ejb 2.1 pfd spec you can read:


17.3.4.2 javax.ejb.EJBContext.setRollbackOnly() method
An enterprise bean with container-managed transaction demarcation can use the setRollbackOnly() method of its EJBContext object to mark the transaction such that the transaction can never commit. Typically, an enterprise bean marks a transaction for rollback to protect data integrity before throwing an application exception, because application exceptions do not automatically cause the Containerc to rollback the transaction.


Same is true for getRollbackOnly().
Maybe the problem lies somewhere else?
 
Kalpesh Soni
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
case 1)
if a method with TX_SUPPORTS is called, without starting transaction ourself then container will not start transaction
now if on exception i try setRollbackOnly() I would get IllegalStateException
case 2)
if the same method having TX_SUPPORTS is called from a method having TX_REQUIRED , container starts transaction. I try to setRollbackOnly() it works
now the questions is
in case 1) how do i find out if the methods having TX_SUPPORTS is running in transaction or not !

:roll: :roll: :roll:
 
Michael Arndt
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. This is not the ultimate answer. But as a suggestion:
Why not throwing a "MethodExceutionFailedException" in the TX_SUPPORTED methods and rolling back in the TX_REQUIRED? I see your academic problem: "How can I know whether I run inside a transaction or not" but I do not see a case where to use it.
And throwing an EJBException as a runtime exception will cause the transaction to rollback automatically, won't it?
Another question to get a better understanding of your problem: The methods type A and B are in the same bean?
 
Kalpesh Soni
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
methods type A and B are in same bean
but methods B can be called either directly , or from inside type A
And the questions is still important
changing trans attrib to TX_REQUIRED will start transactions and i wont get errors
thus "I have to change my code for different entries in ejb-jar.xml"
what is the use of declarative programming then ?
suppose u are using ejbs provided by someone and u dont have access to the source code
and u dont want your methods to run in transactions
what happens then ?
 
Kalpesh Soni
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
another usecase
if it was possible to check

 
Michael Arndt
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a simple session bean, no secrets:

Deployment Descriptor like this:

TestClient:

Output:
mixed = true
required = false
supports = false

Seems to work, doesn't it?
Sample was running with JBoss 2.2
 
Kalpesh Soni
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
same code
running on weblogic 7.0

Output:

[ February 27, 2003: Message edited by: Kalpesh Soni ]
 
Michael Arndt
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to be a topic for the weblogic forum.
Or maybe you should try JBoss.
 
Kalpesh Soni
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

would love to try JBoss
but have to work on a product which in shipping with weblogic 7 in 15 days
 
Michael Arndt
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ February 27, 2003: Message edited by: Michael Arndt ]
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic