Can I use UserTransaction within a CMP Session bean?

Basically the problem is as follow:
I have the following method in a Statefull session bean:
public Whatever do()
processSomething();
notify();
the notify() basically notifying the client that then query for the something that was processed in the processSomething() method.
THE PROBLEM is that the changes have not been committed yet as the do() method is not finished yet and the container has not committed the changes.
THE QUESTION is - can I use UserTransaction inside
processSomething to commit the changes and leave the bean as CMP? I want to leave it as CMP as there are more methods on the bean and I don't want to have to manage the transactions for them.
Anyone has any other ideas?
Thanks in advanced.

Hi again,
The EJB specs say that a stateful Session Bean with CMT is NOT allowed to use the UserTransaction; see page 361 of the EJB2.0 specification. So combining them will not (or should not) work.
I suggest CMT+SessionSynchronization combined with using a flag to indicate whether notify should be called or not. Otherwise, you could try splitting up the bean into two beans: one with CMT and another one without. The one without CMT could use the UserTransaction and notify.
Also, you might want to check http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html
Hope that helps a bit,
Guy
http://www.atomikos.com

Similar Messages

  • How to get the UserTransaction object in  stateless session bean

    Hi, I am using jboss server and jdk5 version and using EJB.
    My Application flow :
    JSP à Action(Struts) à Service Locator à Session bean à Entity Bean(cmp) à DB.
    I tried to get the UserTransaction object in my Action. Its my code.
    InitialContext ctx = new InitialContext();
    UserTransaction uTrans = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    After used uTrans.begin(),uTrans.commit() and uTrans. rollback () also.
    Its working fine .
    But, I used the the same code inside in my session bean its not working.
    Stateless Session Manager Bean code :
    public class SampleManagerBean implements SessionBean {
    public void ejbCreate() throws CreateException {  }
    public void ejbRemove() {  }
    public void ejbActivate() {   }
    public void ejbPassivate() {   }
    public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
         public void createSample() throws EJBException
         try{
                   InitialContext ctx = new InitialContext();
                   UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
              }catch(Exception e) {
              System.out.println(“ Exception === > “+e)
    Its throws the error ie: javax.naming.NameNotFoundException: UserTransaction not bound
    How to get the UserTransaction object in my session bean. Kindly give solution the above errors.
    - Thendral

    first of all, you could just use sessionContext.getUserTransaction(). however, that would only work if your bean is using bean-managed transactions. the default is container-managed transaction, in which case you cannot get a UserTransaction object. if you want to manage transactions, you need to add the TransactionManagementType.BEAN annotation to your ejb.

  • How can I set the value to a session bean from backing bean

    Hi Experts,
    How can I set the value to a session bean from backing bean where I have created getter and setter
    methods for that variable.
    Basically I am using ADFUtils class where I am able to get the value from session bean
    using following expression
    String claimType =
    (String)ADFUtil.invokeEL("#{ClaimValueObj.getClaimType}");
    Thanks
    Gayaz

    Gayaz,
    Wrong Post !!
    Post in JDeveloper and ADF
    Thanks
    --Anil                                                                                                                                                                                                                               

  • Security problem when trying to connect a CMP Session Bean deployed on J2EE

    I am working through Wrox�s book Professional java Mobile Programming and trying to set up the Mobile Positioning project. The book has instructions for Ericson MPS-SDK 3.0 but the only version available now is the 5.0 and these instructions are no longer valid. I have built the application with the Studio 4 IDE and deployed it on an instance of the J2EE reference Implementation and this seems to work fine. However I have built a CMP session bean which should connect to the Ericsson Emulator running on their supplied Eserver and this connection is failing with a security problem. Following is a snippet of the code I have used to instantiate the connection.
    ConnectionFactory con = null;
    con = new ConnectionFactory(true);
    The code compiles with out errors but when I try to test it I get the following error
    java.security.AccessControlException: access denied (java.util.PropertyPermission sun.net.inetaddr.ttl write)
    Any Hints or suggestions would be appreciated.
    Thanks

    Oops!! I meant Session Bean NOT CMP Session Bean

  • Can we call a method in stateless session bean ?

    Can we call a method in stateless session bean in onMessage method?

    Hi,
    The purpose of service locator is to abstract the lookup of the server side services like ejb and DSNs. It should be a normal java class but as such there is no such restriction. You can have a look at the service locator patter at the j2ee blue prints.
    /Ashwani

  • Can I use oracle blob by CMP bean in weblogic 6?

    I use weblogic 6.1(sp3) and Jbuilder 7.when I try to use oracle blob by CMP bean,the
    errors are:
    javax.ejb.FinderException: Exception raised in findByPrimaryKey
    java.io.StreamCorruptedException: InputStream does not contain a serialized object
    What should I do?Is there examples about using oracle blob?
    thanks a lot!

    Great! So what was the problem?
    Regards,
    Slava Imeshev
    "Roger Lee" <[email protected]> wrote in message
    news:[email protected]...
    >
    Finally got it working with CMP, which is my preferred choice (over BMP).
    I read the Excel Spreadsheet into a "byte []" array, and the Entity Beanmapped
    "byte []" to the Blob column in the Oracle table.
    "Slava Imeshev" <[email protected]> wrote:
    Roger,
    I'm not quite sure I undestand the problem. Could you:
    1. Post deployment descriptors in part related to this
    CMP bean?
    2. Post the piece of code that is failing?
    Please post the information above and we will help
    you to hunt the problem down.
    No, I don't have any problems accessing blobs
    from CMP.
    Regards,
    Slava Imeshev
    "Roger Lee" <[email protected]> wrote in message
    news:[email protected]...
    Yes. I have added;
    <dbms_column-type>OracleBlob</dbms-column-type>
    It fails because the locater to the blob, obtained by findBYPrimaryKeyis
    null.
    i.e. an empty_blob() is not created.
    Have you got CMP to access Blobs in WLS 6.1?
    "Slava Imeshev" <[email protected]> wrote:
    Hi Roger,
    Have you tried using OracleBlob as dbms-column-type?
    Also, could you post that part of your code that is failing?
    Regards,
    Slava Imeshev
    "Roger Lee" <[email protected]> wrote in message
    news:[email protected]...
    I can access Clobs using CMP. If you are using the Oracle OCI Driveryou
    do not
    need to add this line.
    However if you are using the Oracle Type 4 Thin drivers you need
    to
    add;
    <dbms_column-type>OracleClob</dbms-column-type>
    to the file;
    weblogic-cmp-rdbms-jar-xml
    This DOES NOT work with Blobs.
    I am unable to get WebLogic 6.1 sp4 persist a Blob to an Oracle
    8.1.x
    table and
    retrieve it using either CMP or BMP.
    Unless any one show me a complete working CMP and BMP example?
    Roger Lee
    Deepak Vohra <[email protected]> wrote:
    BLOB and CLOB DBMS Column Support for the Oracle DBMS
    http://edocs.bea.com/wls/docs61/ejb/cmp.html#1061636
    shybird wrote:
    I use weblogic 6.1(sp3) and Jbuilder 7.when I try to use oracle
    blob
    by CMP bean,the
    errors are:
    javax.ejb.FinderException: Exception raised in findByPrimaryKey
    java.io.StreamCorruptedException: InputStream does not contain
    a
    serialized
    object
    What should I do?Is there examples about using oracle blob?
    thanks a lot!

  • Use direct JDBC with CMP entity bean in one transaction

    I am trying to use direct JDBC call with CMP entity bean within a session
    bean method that requires transaction. The problem is that it appears these
    are not in the same transaction. When I use the JDBC call, the CMP entity
    bean update to the DB has not been committed yet.
    We are using Weblogic 5.1 SP6. The DB is Oracle.
    What I do for the JDBC is get a new connection from the pool using weblogic
    jdbc pool driver.
    Any help would be appreciated.
    Patrick

    Hi. You can do JDBC and invoke CMP EJBs and have this all treated
    as one transaction, if your hand-written code explicitly starts
    a JTS transaction, then uses the jts driver or a TxDataSource to
    get the JDBC connection. Then your code can call transactional
    EJBs and their work will be included in the transaction you started.
    Assuming the bean work went OK, and your manual JDBC went OK, you
    can manually commit the UserTransaction at that time. This is 5.1
    talk. For 6.0, with @PC, this may be even easier...
    Joe
    Patrick Shen wrote:
    >
    But if I do that, then they would not be in the same transaction anymore.
    Is there any way to use JDBC with CMP Entity bean in the same transaction?
    Patrick
    "L'artiste" <[email protected]> wrote in message
    news:[email protected]...
    Are you calling all the CMP create in the session Bean ? If so, beforeyou
    make the JDBC call from the session bean, the CMP in 2. should commit. Try
    to set its attribute to TX_REQUIRES_NEW. This way, the calling client will
    block until this transaction is done (committed) before the execution
    continues. There might be some overhead involved in doing so if you are
    anticipating a lot of users.
    "Patrick Shen" <[email protected]> wrote in message
    news:[email protected]...
    What I am trying to do is:
    In a Session bean method -
    1. create a new CMP entity bean (a new row in DB table)
    2. create another new CMP entity bean that uses previous bean as foreignkey
    3. use JDBC to update the row just created
    And all these 3 calls have to be in one transaction.
    Thanks,
    Patrick
    "L'artiste" <[email protected]> wrote in message
    news:[email protected]...
    Can you give a little bit more information?
    Do you have methods in your session bean that creates this CMP entitybeans?
    It looks like
    you might wanna try to change the isolation level to
    TRANSACTION_READ_COMITTED
    to preven dirty_read.
    "Patrick Shen" <[email protected]> wrote in message
    news:[email protected]...
    I am trying to use direct JDBC call with CMP entity bean within a
    session
    bean method that requires transaction. The problem is that it
    appears
    these
    are not in the same transaction. When I use the JDBC call, the CMP
    entity
    bean update to the DB has not been committed yet.
    We are using Weblogic 5.1 SP6. The DB is Oracle.
    What I do for the JDBC is get a new connection from the pool usingweblogic
    jdbc pool driver.
    Any help would be appreciated.
    Patrick
    PS: Folks: BEA WebLogic is expanding rapidly, with both entry and advanced positions
    for people who want to work with Java, XML, SOAP and E-Commerce infrastructure products.
    We have jobs at Nashua NH, Liberty Corner NJ, San Francisco and San Jose CA.
    Send resumes to [email protected]

  • Using local interfaces for EJB (session bean)

    Hi,
    I�ve a question regarding when to use the Local interfaces(EJBLocal and EJBLocalHome) of a enterprise bean. I understand that calls to enterprise bean can be made locally if the client which is invoking is in the same JVM as that of EJB. I�ve written a web client (servlet) which is packaged in a EAR and this servlet is trying to invoke a session bean which is in a �different� EAR using local interfaces. Both the EARs have been deployed in a single server (websphere 6.0 server). It didn�t work for me this way�..If I package the servlet in the same EAR of session bean then it works fine.
    So is this to say that both EARs are not running on the same JVM? Or should it work even if the client and the session bean are in different EARs but in same server?
    Can anyone explain me the fundamentals behind this.
    Thanks in advance

    Local access is only portable within the same .ear. For example, the Java EE SDK and SUN's
    application servers have never supported local EJB access from a web/EJB component in a different
    .ear. One issue is that local access requires that both the caller and target EJB have the same
    classloader. By definition, different Java EE applications have distinct classloaders. In addition,
    in Java EE 5 persistence context propagation does not span applications, so it wouldn't work in the
    local case.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Losing UserTransaction state in Stateful session bean

    I have a UserTransaction I wish to begin and commit in different methods of a Stateful session bean. I have 2 methods to test this on the session bean:
    public void beginTransaction()
    trans = context.getUserTransaction() ;
    trans.begin() ;
    public void commitTransaction()
    trans = context.getUserTransaction() ;
    trans.commit() ;
    If I call these methods from one Perform method in a Struts action all works fine. If I call the methods in different Struts actions (storing the session bean handle on the HTTPSession in the first for retrieval in the second) the second call fails with the following exception:
    java.lang.IllegalStateException: No active Transaction
    The state of the transaction on the second call is STATUS_NO_TRANSACTION. I am certain that I have lost no state on the session bean and that using handles gives me the correct bean since I have written some state to test this. Basically something seems to close the transaction between the end of the first Perform method and the beginning of the second (I am of course assuming this is a valid thing to do).
    My session bean descriptor has <transaction-type>Bean</transaction-type>, and I am using OC4J.
    If anyone can point out what it is I am doing wrong I would be grateful!
    James.

    Sorry, I have re-checked my code and I believe I found the problem.
    I was beginning my transaction inside ejbCreate() and trying to commit/rollback in another method. This works in JBoss 3.2 but does not work in either OC4J or WebLogic 7.
    If I begin my transaction in a business method and commit/rollback in another method, everything works fine. (It also seems to work fine in 9.0.3 this way).
    So I am not sure whether this is a bug in 9iAS/WLS, or a bug in JBoss, or something that is left "vague" in the J2EE spec. Unfortunately, examples on bean-managed transactions are thin on the ground generally (the usual advice being not to use them, which I definitely agree with!).
    If you believe that the behaviour I describe is a bug in 9iAS, I can send a simple EJB test case.
    Keith

  • Using only one method in session bean to create web service

    Hi all,
    I hhave a scenario where i am inserting and retrieving data from dict table using web service.
    For this i have created a session bean and a wrapper class.
    The session bean has two methods: insertRecords(), and viewRec().
    so while creating a web service i need to include two methods.
    I want to have only one method where i can pass a parameter as operation and if it is "I", then i can call the insert method and if it is "S" i can call view method.
    I tried doing that bt i am stuck up with the return type.
    Insert method has return type as array of wrapper class and
    view method has wrapper class as return type ...
    Is this scenario possible..??
    or is there any other way to do this???
    Plz let me knw..
    Thankls n regards,
    Ankita

    Hi Siddharth,
    Im really sorry..
    i cudnt  get u ..
    Actually these r methods:
    public DemoDicModel[] viewRecords()
    and
    public DemoDicModel insertRecords(
              String title,
              String desc,
              String status)
    and im trying this:
    public DemoDicModel[] getMethods(String operation,String title,String desc, String st)
    DemoDicModel[] demoModel =null;
    DemoDicModel model = new DemoDicModel();
    if(operation == "show")
          demoModel = viewRecords();
    if(operation == "ins")
          model = insertRecords(title,desc,st);
          model.setMsg("RECORDS GENERATED");
          demoModel=
    return demoModel;
    im stuck up with insert operation.
    can  u plz explain me in detail.
    thanks,
    ankita

  • Can we implement "Service Locator" in Stateless Session Bean??

    Hi,
    My enterprise application is using Stateless Session Bean. To increase the performace , I think of implementing "service Locator" pattern so as to cache the EJBHome objects in order to avoid looking up Home object every time. I want to know whether this will work out in case of stateless session bean??
    Thanks for ur help.

    Hi,
    The purpose of service locator is to abstract the lookup of the server side services like ejb and DSNs. It should be a normal java class but as such there is no such restriction. You can have a look at the service locator patter at the j2ee blue prints.
    /Ashwani

  • Screenshots for Search option using Enity  object(donot want session bean)

    I want to create Entity object(donot want session bean and Enity diagram) with search option. so any one help me. i could not find (b13895_oracle10g) PDF

    Can you elaborate a little more?
    Do you mean ADF Entity objects or EJB entities from tables?
    For ADF Entities -
    You can create Business components from tables wizard from the New gallery and follow the steps. This creates your entites which are xml files and also view objects for which data controls get created, which you can then use in your jspx.
    For EJB entities though you need to create a session bean or a service facade.
    Thanks.

  • Using TableLocking API in Stateless Session Bean through WD application

    Hi All,
    We have develpoed a webDynpro application which involved Jav Dictionary Table.
    We have given UI for Creation, Updation and Deletion of the table.For database connection we have used Stateless Session Bean.
    we have the requirement of Locking the Table record when one user is either editing or deleting the record of Table from UI, so any other user cannot update or delete the same record.
    To implement the above functionality, we have used TableLocking API with lifetime as userSession in the Stateless Session Bean to acquire a Lock for particular record.
    With lifetime as usersession the record should get unLocked automatically, if the session of application is expired and record is not unLocked Explicitly.
    We are calling the Session Bean from Webdynpro application to acquire a lock, When the Dynpro application expires the locked record should get unlocked automatically as the lifetime is defined as usersession,But the record remains unlocked only even after expiration of the application sessionand deadlock occurs for that record.
    So if anyone can suggest the solution for the above problem.
    Or some other method to Lock Particular Record from application.
    Thanks in advance.
    Regards,
    Shruti.

    HI,
    Can you resolve this issue?
    I have the same scenary, could you give me some tips?
    Thanks,
    Freddy F

  • Can I use PDK within Orion Application Server

    I usually run applications within Orion Application Server but I`d like to use portlets developed with PDK.
    Please submit responses to [email protected]
    Thanks

    hi,
    PDKJava V2 is J2EE compatible and comes as an EAR file. You can deploy jpdk.ear , just the same way you deploy other J2EE applicatons.
    --Sriram                                                                                                                                                                                                                                                                                                           

  • GridControl;JBO: How can i use ArrayAccess within custom renderer for GridControl

    When i use ArrayAccess for access rows around current, or to
    access to hidden columns in rendering row, within
    TableCellRenderer, then my program stays in infinite loop in
    this TableCellRenderer. But when i use same code to plain print
    query results, all work fine.
    Here's my code:
    public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus, int
    row, int column) {
    __null:
    if (value != null) {
    dataItemView.setViewStart(row);
    int[] k = {0,interested_column};
    ImmediateAccess ia = (ImmediateAccess)
    arrayAccess.getItemByCoordinates(k);
    cur = ia.getValueAsObject();
    if (cur == null) cur = ia.getValueAsString();
    if (cur == null) break __null;
    My debug printing shows that after setViewStart(row),
    getViewStart() != row.
    Is there any available sources for Oracle JBO implementation of
    InfoBus ?
    P.S. also in renderer, when ImmediateAccess holds String, then
    getValueAsObject() returns null, why ???

    When i use ArrayAccess for access rows around current, or to
    access to hidden columns in rendering row, within
    TableCellRenderer, then my program stays in infinite loop in
    this TableCellRenderer. But when i use same code to plain print
    query results, all work fine.
    Here's my code:
    public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus, int
    row, int column) {
    __null:
    if (value != null) {
    dataItemView.setViewStart(row);
    int[] k = {0,interested_column};
    ImmediateAccess ia = (ImmediateAccess)
    arrayAccess.getItemByCoordinates(k);
    cur = ia.getValueAsObject();
    if (cur == null) cur = ia.getValueAsString();
    if (cur == null) break __null;
    My debug printing shows that after setViewStart(row),
    getViewStart() != row.
    Is there any available sources for Oracle JBO implementation of
    InfoBus ?
    P.S. also in renderer, when ImmediateAccess holds String, then
    getValueAsObject() returns null, why ???

Maybe you are looking for

  • Acrobat 9 Large File Issues?

    I work with very large Excel files that I need to turn into pdf's.  Very large meaning 30,000 to 50,000 rows in the spreadsheet.  Once turned into a pdf it is 586 pages long.  I had Adobe Acrobat 9 Standard and I began to experience issues.  If I wer

  • Importing a csv file into addressbook

    So I did a search & found this question has come up quite often, but with the person having a slightly different problem, so here goes. I am trying to import a csv file into address book, when I go import -> text tile it comes up like it should do an

  • How to convert SQL server stored procedures to Oracle 11g

    Hi Experts, In SQL server 30 stored procedures are there how to convert all the stored procedure from SQL server to Oracle 11g. Please help me, Thanks.

  • Database Diff Wizard Tool problem

    Using Oracle SQL Developer 1.5.1 Build 5440. Third Party Extension jtds-1.1.2.jar I'm trying to determine if the Database Diff Wizard Tool contains functionality to allow/support diff compares between objects found in an Oracle Db instance and object

  • SOAP:14 - Unexpected element

    Hi, while trying to consume an external WS from our ECC 6.4 ABAP system, I'm getting the following error message: CODE - SOAP:14 ERRORTEXT - Unexpected element -el=script ns= More detailed information from RFC-Trace: XRFC> INFO 16:41:40: SOAP SESSION