1 Reply Latest reply on May 18, 2007 6:16 PM by wpernath

    DAO and Entity Beans

    anandnatraj

      I am using a DAO Insert and trying to load the Remote Entity bean for the record which is just created under a single transaction as below

      public MyEntity createSomeInfoMethod()
      {
      MyEntityHome entityHome = lookUp("MyEntity");
      long id = SomeDAO.insertRecord(valueObject);
      MyEntity mro = MyEntityHome.findByPrimaryKey(id);
      return mro;
      }

      createSomeInfoMethod() is a stateless session method under a transaction control.
      id is returned as the primaryKey of the record which is inserted using a DAO. (it is not null). But on the next line where I try to find the findByPrimaryKey I am getting following exception

      javax.ejb.ObjectNotFoundException: No such entity!


      MyEntityHome, MyEntity are the Home and Remote respectively for a CMP Bean. Am I missing anything basically? The HOME is looked up correctly. No issues in that.

      Please help.

        • 1. Re: DAO and Entity Beans
          wpernath

          Hi,

          there are some things you should keep in mind when you are doing things like this. ;-)

          - Are you mixing user transactions with CMT?
          - Is SomeDAO.insert() committing the data to the database?
          - What are the CMT settings of the findByPrimaryKey() method?
          - And what are the CMT settings of the createSomeInfoMethod()?

          What I want to say is: Only if the DAO method has really committed the data, you are able to read them using an entity finder.

          HTH,
          Wanja