• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help on IllegalStateException

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have built a session bean which will access CMP entity bean to create the record. However, I need to have an unique primary key before create the record. So I call a stateless session bean to retreive next sequence number from oracle DB, and then create the entity with the new PK.
CounterLocal counter = counterHome.create() ;
user = userHome.create(counter.getNextVal, name, post, tel) ;
When I run in WebSphere UTest Client, it throw the following exception :
TransactionIm E WTRN0062E: An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction.
LocalTransact E J2CA0030E: Method enlist caught java.lang.IllegalStateException

Why ? Is it due to my setting in WSAD incorrect ?
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing the same problem. Can someone help me out please?
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're triggering a commit between what WebSphere interprets as two separate databases, via it seeing two separate connections. The first call to look up the record is the first database and the second call on the CMP bean is the second database. WebSphere does not understand that these are the same database, although by using resource references it can optimize away the 2PC, but thats not guarenteed.

In this case two indepedent database calls isn't neccessary so I'd suggest resolving this in one of three ways...
  • Create a finder method on the CMP that searches for max record. This way all database calls are controlled by the CMP and WebSphere won't think your making two separate connections.
  • Add the logic to retrieve the key inside the CMP itself.
  • Add the logic to create the primary key into the database itself since most can do auto-increment fields.

  •  
    author
    Posts: 181
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    WebSphere can guarantee the same connection following the advice in this article:

    http://www-128.ibm.com/developerworks/websphere/library/techarticles/0404_tang/0404_tang.html
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic