glassfish
  1. glassfish
  2. GLASSFISH-3389

Cannot get id of managed object instance in session bean method

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 9.0pe
    • Fix Version/s: not determined
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      3,389
    • Status Whiteboard:
      Hide

      HIGH

      Show
      HIGH

      Description

      I don't know what the correct selection for the "Found in version" field is. The
      Glassfish version is Glassfish Beta 3 (b50g-beta3).

      I had posted a description of the problem in the glassfish forum:

      http://forums.java.net/jive/thread.jspa?threadID=28805&tstart=0

      Gordon Yorke ("gyorke") replied that I should file an issue as the example code
      should work.

      Expected behavior: in session bean method "testSaveParent" it should be possible
      to get the id of the "child" object after it was persisted. However
      "child.getId()" returns null.

      ------------------- Child class -----------------
      @Entity
      public class Child implements Serializable {
      private Long id;
      private Parent parent;

      @ManyToOne
      public Parent getParent() {
      return parent;
      }

      public void setParent(Parent parent) {
      this.parent = parent;
      }

      @Id
      @GeneratedValue
      public Long getId() {
      return id;
      }

      public void setId(Long id) {
      this.id = id;
      }
      }
      --------------- Parent class -------------
      @Entity
      public class Parent implements Serializable {
      private Long id;
      private List<Child> children;

      @OneToMany(mappedBy="parent")
      public List<Child> getChildren() {
      return children;
      }

      public void setChildren(List<Child> children) {
      this.children = children;
      }

      @Id
      @GeneratedValue
      public Long getId() {
      return id;
      }

      public void setId(Long id) {
      this.id = id;
      }
      }

      ---------------- Session bean method -------------------
      @Stateless
      @TransactionManagement(value=TransactionManagementType.CONTAINER)
      public class CustomerSession implements CustomerSessionRemote,
      CustomerSessionLocal {

      @javax.persistence.PersistenceContext(unitName="backoffice")
      private EntityManager em;

      public Child testSaveParent(Parent parent) {
      em.persist(parent);

      Child child = new Child();
      child.setParent(parent);

      parent.getChildren().add(child);

      em.merge(parent);
      em.persist(child);

      System.out.println("Session bean get new id " + child.getId());

      return child;
      }
      }
      --------- invoking the session bean method ------------------
      Parent parent = new Parent();
      Child child = session.testSaveParent(parent);

      System.out.println("id is " + child.getId());

        Activity

        Hide
        gfbugbridge added a comment -

        <BT6583662>

        Show
        gfbugbridge added a comment - <BT6583662>
        Hide
        pkrogh added a comment -

        Downgrading from a P3 to a P4HIGH.

        I am doing so because of the workarounds that were mentioned in the forum post
        associated in the bug.

        Show
        pkrogh added a comment - Downgrading from a P3 to a P4HIGH. I am doing so because of the workarounds that were mentioned in the forum post associated in the bug.
        Hide
        pkrogh added a comment -

        adding myself to cc list

        Show
        pkrogh added a comment - adding myself to cc list
        Hide
        Tom Mueller added a comment -

        Bulk change to set fix version to "not determined" where the issue is open but the value is for a released version.

        Show
        Tom Mueller added a comment - Bulk change to set fix version to "not determined" where the issue is open but the value is for a released version.

          People

          • Assignee:
            tware
            Reporter:
            smuehlst
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: