Creation of a related EJB2 entity fail with error

Solution Unverified - Updated -

Issue

  • If business code inside the entity is invoked during creation the code fail
  • "JBAS014171: Instance for PK [....] already registered" during entity creation after the ejbCreate method was invoked
  • After migration from EAP4 or EAP5 to EAP6 the entity could not created and throw and Exception with the error code "JBAS014171"

A code Example

class ParentBMPEntityBean {
  public ParentBMPPK ejbCreateWithChildSamePK(String code, long id, String name) throws CreateException {
    ParentBMPPK pk = new ParentBMPPK(code, id);

    setCode(code);
    setId(id);
    setName(name);

    try {
      ChildBMPEntityLocalHome childHome = (ChildBMPEntityLocalHome) new InitialContext().lookup("java:app/EJB2examples-bmp-one2one-ejb/ChildBMPEntity!de.wfink.ejb2.examples.bmp.ChildBMPEntityLocalHome");
      childHome.create(this.code, this.id, this.id, "ChildBMP for "+this.name);
    } catch (NamingException e) {
      new RuntimeException("Could not lookup ChildBMPEntityLocalHome",e);
    }

    return (pk);
  }

  public void ejbPostCreateWithChildSamePK(String code, long id, String name) {}
}

class ChildBMPEntityBean {
  public ChildBMPEntityPK ejbCreate(String code, Long id, Long parentId, String name) {
    ...
    // check that the parent exists
    try {
      setParent(parentLocalHome.findById(parentId));
    }catch(Exception e) {
      throw new RuntimeException("Parent does not exists");
    }
  }
}

Environment

  • Red Hat Enterprise Application Platform (EAP)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.