7 Replies Latest reply: Sep 6, 2010 5:30 AM by 795665 RSS

    Preexisting Entity Exception

    795665
      Hi all

      I have a MySQL database with two tables, Table A and Table B.
      Table A has a one to many relationship with Table B eg.

      (One) ---- (Many)
      Table A ---- Table B

      When I generate the entity classes of the tables I get 3 entity classes:
      TableA
      TableB
      TableBPK

      I have written a piece of code to persist some records into the database but I keep getting a preexisting entity exception from the second record and on.
      If I restart my application I can write a new record but then after the first record I get the same error. Why? Here is my code:
      TableAJpaController controllerA = new TableAJpaController();
              
      TableA tableA = new TableA();
      tableA.setDescription("Record A");
      controllerA.create(tableA);
      
      TableBJpaController controllerB = new TableBJpaController();
      
      TableB tableB1 = new TableB();
      tableB1.setDescription("Record B1");
      tableB1.setTableA(tableA);
      controllerB.create(tableB1);
      
      TableB tableB2 = new TableB();
      tableB2.setDescription("Record B2");
      tableB2.setTableA(tableA);
      controllerB.create(tableB2);
      Any help would be greatly appreciated.

      Regards
        • 1. Re: Preexisting Entity Exception
          Cdelahun-Oracle
          Hello,

          What is the primary key, and have you configured sequencing for it? If not, that is likely why you can only run this code once - a second run through has the entity using the same value as the first time its run.

          Best Regards,
          Chris
          • 2. Re: Preexisting Entity Exception
            795665
            Here are the structures of my tables:

            Table A
            idTableA INT(10) AI PK NN
            Description Varchar(20) NN

            Table B
            idTableB INT(10) AI PK NN
            idTableA INT(10) PK NN
            Description Varchar(20) NN

            I don't set the id's because toplink handles the auto increment for me.

            Regards
            Cobus
            • 3. Re: Preexisting Entity Exception
              Cdelahun-Oracle
              How do the entities look, what are the mappings used, and what does the TableBJpaController create method do? When does the exception occur - on the create A or create b?

              Regards,
              Chris
              • 4. Re: Preexisting Entity Exception
                795665
                Here is Table A entity class:
                @Entity
                @Table(name = "TableA", catalog = "test", schema = "")
                @NamedQueries({
                    @NamedQuery(name = "TableA.findAll", query = "SELECT t FROM TableA t"),
                    @NamedQuery(name = "TableA.findByIdTableA", query = "SELECT t FROM TableA t WHERE t.idTableA = :idTableA"),
                    @NamedQuery(name = "TableA.findByDescription", query = "SELECT t FROM TableA t WHERE t.description = :description")})
                public class TableA implements Serializable {
                    private static final long serialVersionUID = 1L;
                    @Id
                    @GeneratedValue(strategy = GenerationType.IDENTITY)
                    @Basic(optional = false)
                    @Column(name = "idTableA", nullable = false)
                    private Integer idTableA;
                    @Basic(optional = false)
                    @Column(name = "Description", nullable = false, length = 20)
                    private String description;
                    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tableA", fetch = FetchType.LAZY)
                    private Collection<TableB> tableBCollection;
                
                    public TableA() {
                    }
                
                    public TableA(Integer idTableA) {
                        this.idTableA = idTableA;
                    }
                
                    public TableA(Integer idTableA, String description) {
                        this.idTableA = idTableA;
                        this.description = description;
                    }
                
                    public Integer getIdTableA() {
                        return idTableA;
                    }
                
                    public void setIdTableA(Integer idTableA) {
                        this.idTableA = idTableA;
                    }
                
                    public String getDescription() {
                        return description;
                    }
                
                    public void setDescription(String description) {
                        this.description = description;
                    }
                
                    public Collection<TableB> getTableBCollection() {
                        return tableBCollection;
                    }
                
                    public void setTableBCollection(Collection<TableB> tableBCollection) {
                        this.tableBCollection = tableBCollection;
                    }
                
                    @Override
                    public int hashCode() {
                        int hash = 0;
                        hash += (idTableA != null ? idTableA.hashCode() : 0);
                        return hash;
                    }
                
                    @Override
                    public boolean equals(Object object) {
                        // TODO: Warning - this method won't work in the case the id fields are not set
                        if (!(object instanceof TableA)) {
                            return false;
                        }
                        TableA other = (TableA) object;
                        if ((this.idTableA == null && other.idTableA != null) || (this.idTableA != null && !this.idTableA.equals(other.idTableA))) {
                            return false;
                        }
                        return true;
                    }
                
                    @Override
                    public String toString() {
                        return "test.tables.TableA[idTableA=" + idTableA + "]";
                    }
                And here is Table B:
                @Entity
                @Table(name = "TableB", catalog = "test", schema = "")
                @NamedQueries({
                    @NamedQuery(name = "TableB.findAll", query = "SELECT t FROM TableB t"),
                    @NamedQuery(name = "TableB.findByIdTableB", query = "SELECT t FROM TableB t WHERE t.tableBPK.idTableB = :idTableB"),
                    @NamedQuery(name = "TableB.findByIdTableA", query = "SELECT t FROM TableB t WHERE t.tableBPK.idTableA = :idTableA"),
                    @NamedQuery(name = "TableB.findByDescription", query = "SELECT t FROM TableB t WHERE t.description = :description")})
                public class TableB implements Serializable {
                    private static final long serialVersionUID = 1L;
                    @EmbeddedId
                    protected TableBPK tableBPK;
                    @Basic(optional = false)
                    @Column(name = "Description", nullable = false, length = 20)
                    private String description;
                    @JoinColumn(name = "idTableA", referencedColumnName = "idTableA", nullable = false, insertable = false, updatable = false)
                    @ManyToOne(optional = false, fetch = FetchType.LAZY)
                    private TableA tableA;
                
                    public TableB() {
                    }
                
                    public TableB(TableBPK tableBPK) {
                        this.tableBPK = tableBPK;
                    }
                
                    public TableB(TableBPK tableBPK, String description) {
                        this.tableBPK = tableBPK;
                        this.description = description;
                    }
                
                    public TableB(int idTableB, int idTableA) {
                        this.tableBPK = new TableBPK(idTableB, idTableA);
                    }
                
                    public TableBPK getTableBPK() {
                        return tableBPK;
                    }
                
                    public void setTableBPK(TableBPK tableBPK) {
                        this.tableBPK = tableBPK;
                    }
                
                    public String getDescription() {
                        return description;
                    }
                
                    public void setDescription(String description) {
                        this.description = description;
                    }
                
                    public TableA getTableA() {
                        return tableA;
                    }
                
                    public void setTableA(TableA tableA) {
                        this.tableA = tableA;
                    }
                
                    @Override
                    public int hashCode() {
                        int hash = 0;
                        hash += (tableBPK != null ? tableBPK.hashCode() : 0);
                        return hash;
                    }
                
                    @Override
                    public boolean equals(Object object) {
                        // TODO: Warning - this method won't work in the case the id fields are not set
                        if (!(object instanceof TableB)) {
                            return false;
                        }
                        TableB other = (TableB) object;
                        if ((this.tableBPK == null && other.tableBPK != null) || (this.tableBPK != null && !this.tableBPK.equals(other.tableBPK))) {
                            return false;
                        }
                        return true;
                    }
                
                    @Override
                    public String toString() {
                        return "test.tables.TableB[tableBPK=" + tableBPK + "]";
                    }
                And then Table B PK:
                @Embeddable
                public class TableBPK implements Serializable {
                    @Basic(optional = false)
                    @Column(name = "idTableB", nullable = false)
                    private int idTableB;
                    @Basic(optional = false)
                    @Column(name = "idTableA", nullable = false)
                    private int idTableA;
                
                    public TableBPK() {
                    }
                
                    public TableBPK(int idTableB, int idTableA) {
                        this.idTableB = idTableB;
                        this.idTableA = idTableA;
                    }
                
                    public int getIdTableB() {
                        return idTableB;
                    }
                
                    public void setIdTableB(int idTableB) {
                        this.idTableB = idTableB;
                    }
                
                    public int getIdTableA() {
                        return idTableA;
                    }
                
                    public void setIdTableA(int idTableA) {
                        this.idTableA = idTableA;
                    }
                
                    @Override
                    public int hashCode() {
                        int hash = 0;
                        hash += (int) idTableB;
                        hash += (int) idTableA;
                        return hash;
                    }
                
                    @Override
                    public boolean equals(Object object) {
                        // TODO: Warning - this method won't work in the case the id fields are not set
                        if (!(object instanceof TableBPK)) {
                            return false;
                        }
                        TableBPK other = (TableBPK) object;
                        if (this.idTableB != other.idTableB) {
                            return false;
                        }
                        if (this.idTableA != other.idTableA) {
                            return false;
                        }
                        return true;
                    }
                
                    @Override
                    public String toString() {
                        return "test.tables.TableBPK[idTableB=" + idTableB + ", idTableA=" + idTableA + "]";
                    }
                Here is my JPA controller classes that I generated from the entity classes.
                Table A controller:
                public class TableAJpaController {
                
                    public TableAJpaController() {
                        emf = Persistence.createEntityManagerFactory("TestPU");
                    }
                    private EntityManagerFactory emf = null;
                
                    public EntityManager getEntityManager() {
                        return emf.createEntityManager();
                    }
                
                    public void create(TableA tableA) {
                        if (tableA.getTableBCollection() == null) {
                            tableA.setTableBCollection(new ArrayList<TableB>());
                        }
                        EntityManager em = null;
                        try {
                            em = getEntityManager();
                            em.getTransaction().begin();
                            Collection<TableB> attachedTableBCollection = new ArrayList<TableB>();
                            for (TableB tableBCollectionTableBToAttach : tableA.getTableBCollection()) {
                                tableBCollectionTableBToAttach = em.getReference(tableBCollectionTableBToAttach.getClass(), tableBCollectionTableBToAttach.getTableBPK());
                                attachedTableBCollection.add(tableBCollectionTableBToAttach);
                            }
                            tableA.setTableBCollection(attachedTableBCollection);
                            em.persist(tableA);
                            for (TableB tableBCollectionTableB : tableA.getTableBCollection()) {
                                TableA oldTableAOfTableBCollectionTableB = tableBCollectionTableB.getTableA();
                                tableBCollectionTableB.setTableA(tableA);
                                tableBCollectionTableB = em.merge(tableBCollectionTableB);
                                if (oldTableAOfTableBCollectionTableB != null) {
                                    oldTableAOfTableBCollectionTableB.getTableBCollection().remove(tableBCollectionTableB);
                                    oldTableAOfTableBCollectionTableB = em.merge(oldTableAOfTableBCollectionTableB);
                                }
                            }
                            em.getTransaction().commit();
                        } finally {
                            if (em != null) {
                                em.close();
                            }
                        }
                    }
                
                    public void edit(TableA tableA) throws IllegalOrphanException, NonexistentEntityException, Exception {
                        EntityManager em = null;
                        try {
                            em = getEntityManager();
                            em.getTransaction().begin();
                            TableA persistentTableA = em.find(TableA.class, tableA.getIdTableA());
                            Collection<TableB> tableBCollectionOld = persistentTableA.getTableBCollection();
                            Collection<TableB> tableBCollectionNew = tableA.getTableBCollection();
                            List<String> illegalOrphanMessages = null;
                            for (TableB tableBCollectionOldTableB : tableBCollectionOld) {
                                if (!tableBCollectionNew.contains(tableBCollectionOldTableB)) {
                                    if (illegalOrphanMessages == null) {
                                        illegalOrphanMessages = new ArrayList<String>();
                                    }
                                    illegalOrphanMessages.add("You must retain TableB " + tableBCollectionOldTableB + " since its tableA field is not nullable.");
                                }
                            }
                            if (illegalOrphanMessages != null) {
                                throw new IllegalOrphanException(illegalOrphanMessages);
                            }
                            Collection<TableB> attachedTableBCollectionNew = new ArrayList<TableB>();
                            for (TableB tableBCollectionNewTableBToAttach : tableBCollectionNew) {
                                tableBCollectionNewTableBToAttach = em.getReference(tableBCollectionNewTableBToAttach.getClass(), tableBCollectionNewTableBToAttach.getTableBPK());
                                attachedTableBCollectionNew.add(tableBCollectionNewTableBToAttach);
                            }
                            tableBCollectionNew = attachedTableBCollectionNew;
                            tableA.setTableBCollection(tableBCollectionNew);
                            tableA = em.merge(tableA);
                            for (TableB tableBCollectionNewTableB : tableBCollectionNew) {
                                if (!tableBCollectionOld.contains(tableBCollectionNewTableB)) {
                                    TableA oldTableAOfTableBCollectionNewTableB = tableBCollectionNewTableB.getTableA();
                                    tableBCollectionNewTableB.setTableA(tableA);
                                    tableBCollectionNewTableB = em.merge(tableBCollectionNewTableB);
                                    if (oldTableAOfTableBCollectionNewTableB != null && !oldTableAOfTableBCollectionNewTableB.equals(tableA)) {
                                        oldTableAOfTableBCollectionNewTableB.getTableBCollection().remove(tableBCollectionNewTableB);
                                        oldTableAOfTableBCollectionNewTableB = em.merge(oldTableAOfTableBCollectionNewTableB);
                                    }
                                }
                            }
                            em.getTransaction().commit();
                        } catch (Exception ex) {
                            String msg = ex.getLocalizedMessage();
                            if (msg == null || msg.length() == 0) {
                                Integer id = tableA.getIdTableA();
                                if (findTableA(id) == null) {
                                    throw new NonexistentEntityException("The tableA with id " + id + " no longer exists.");
                                }
                            }
                            throw ex;
                        } finally {
                            if (em != null) {
                                em.close();
                            }
                        }
                    }
                
                    public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
                        EntityManager em = null;
                        try {
                            em = getEntityManager();
                            em.getTransaction().begin();
                            TableA tableA;
                            try {
                                tableA = em.getReference(TableA.class, id);
                                tableA.getIdTableA();
                            } catch (EntityNotFoundException enfe) {
                                throw new NonexistentEntityException("The tableA with id " + id + " no longer exists.", enfe);
                            }
                            List<String> illegalOrphanMessages = null;
                            Collection<TableB> tableBCollectionOrphanCheck = tableA.getTableBCollection();
                            for (TableB tableBCollectionOrphanCheckTableB : tableBCollectionOrphanCheck) {
                                if (illegalOrphanMessages == null) {
                                    illegalOrphanMessages = new ArrayList<String>();
                                }
                                illegalOrphanMessages.add("This TableA (" + tableA + ") cannot be destroyed since the TableB " + tableBCollectionOrphanCheckTableB + " in its tableBCollection field has a non-nullable tableA field.");
                            }
                            if (illegalOrphanMessages != null) {
                                throw new IllegalOrphanException(illegalOrphanMessages);
                            }
                            em.remove(tableA);
                            em.getTransaction().commit();
                        } finally {
                            if (em != null) {
                                em.close();
                            }
                        }
                    }
                
                    public List<TableA> findTableAEntities() {
                        return findTableAEntities(true, -1, -1);
                    }
                
                    public List<TableA> findTableAEntities(int maxResults, int firstResult) {
                        return findTableAEntities(false, maxResults, firstResult);
                    }
                
                    private List<TableA> findTableAEntities(boolean all, int maxResults, int firstResult) {
                        EntityManager em = getEntityManager();
                        try {
                            Query q = em.createQuery("select object(o) from TableA as o");
                            if (!all) {
                                q.setMaxResults(maxResults);
                                q.setFirstResult(firstResult);
                            }
                            return q.getResultList();
                        } finally {
                            em.close();
                        }
                    }
                
                    public TableA findTableA(Integer id) {
                        EntityManager em = getEntityManager();
                        try {
                            return em.find(TableA.class, id);
                        } finally {
                            em.close();
                        }
                    }
                
                    public int getTableACount() {
                        EntityManager em = getEntityManager();
                        try {
                            Query q = em.createQuery("select count(o) from TableA as o");
                            return ((Long) q.getSingleResult()).intValue();
                        } finally {
                            em.close();
                        }
                    }
                
                }
                And Table B controller:
                public class TableBJpaController {
                
                    public TableBJpaController() {
                        emf = Persistence.createEntityManagerFactory("TestPU");
                    }
                    private EntityManagerFactory emf = null;
                
                    public EntityManager getEntityManager() {
                        return emf.createEntityManager();
                    }
                
                    public void create(TableB tableB) throws PreexistingEntityException, Exception {
                        if (tableB.getTableBPK() == null) {
                            tableB.setTableBPK(new TableBPK());
                        }
                        tableB.getTableBPK().setIdTableA(tableB.getTableA().getIdTableA());
                        EntityManager em = null;
                        try {
                            em = getEntityManager();
                            em.getTransaction().begin();
                            TableA tableA = tableB.getTableA();
                            if (tableA != null) {
                                tableA = em.getReference(tableA.getClass(), tableA.getIdTableA());
                                tableB.setTableA(tableA);
                            }
                            em.persist(tableB);
                            if (tableA != null) {
                                tableA.getTableBCollection().add(tableB);
                                tableA = em.merge(tableA);
                            }
                            em.getTransaction().commit();
                        } catch (Exception ex) {
                            if (findTableB(tableB.getTableBPK()) != null) {
                                throw new PreexistingEntityException("TableB " + tableB + " already exists.", ex);
                            }
                            throw ex;
                        } finally {
                            if (em != null) {
                                em.close();
                            }
                        }
                    }
                
                    public void edit(TableB tableB) throws NonexistentEntityException, Exception {
                        tableB.getTableBPK().setIdTableA(tableB.getTableA().getIdTableA());
                        EntityManager em = null;
                        try {
                            em = getEntityManager();
                            em.getTransaction().begin();
                            TableB persistentTableB = em.find(TableB.class, tableB.getTableBPK());
                            TableA tableAOld = persistentTableB.getTableA();
                            TableA tableANew = tableB.getTableA();
                            if (tableANew != null) {
                                tableANew = em.getReference(tableANew.getClass(), tableANew.getIdTableA());
                                tableB.setTableA(tableANew);
                            }
                            tableB = em.merge(tableB);
                            if (tableAOld != null && !tableAOld.equals(tableANew)) {
                                tableAOld.getTableBCollection().remove(tableB);
                                tableAOld = em.merge(tableAOld);
                            }
                            if (tableANew != null && !tableANew.equals(tableAOld)) {
                                tableANew.getTableBCollection().add(tableB);
                                tableANew = em.merge(tableANew);
                            }
                            em.getTransaction().commit();
                        } catch (Exception ex) {
                            String msg = ex.getLocalizedMessage();
                            if (msg == null || msg.length() == 0) {
                                TableBPK id = tableB.getTableBPK();
                                if (findTableB(id) == null) {
                                    throw new NonexistentEntityException("The tableB with id " + id + " no longer exists.");
                                }
                            }
                            throw ex;
                        } finally {
                            if (em != null) {
                                em.close();
                            }
                        }
                    }
                
                    public void destroy(TableBPK id) throws NonexistentEntityException {
                        EntityManager em = null;
                        try {
                            em = getEntityManager();
                            em.getTransaction().begin();
                            TableB tableB;
                            try {
                                tableB = em.getReference(TableB.class, id);
                                tableB.getTableBPK();
                            } catch (EntityNotFoundException enfe) {
                                throw new NonexistentEntityException("The tableB with id " + id + " no longer exists.", enfe);
                            }
                            TableA tableA = tableB.getTableA();
                            if (tableA != null) {
                                tableA.getTableBCollection().remove(tableB);
                                tableA = em.merge(tableA);
                            }
                            em.remove(tableB);
                            em.getTransaction().commit();
                        } finally {
                            if (em != null) {
                                em.close();
                            }
                        }
                    }
                
                    public List<TableB> findTableBEntities() {
                        return findTableBEntities(true, -1, -1);
                    }
                
                    public List<TableB> findTableBEntities(int maxResults, int firstResult) {
                        return findTableBEntities(false, maxResults, firstResult);
                    }
                
                    private List<TableB> findTableBEntities(boolean all, int maxResults, int firstResult) {
                        EntityManager em = getEntityManager();
                        try {
                            Query q = em.createQuery("select object(o) from TableB as o");
                            if (!all) {
                                q.setMaxResults(maxResults);
                                q.setFirstResult(firstResult);
                            }
                            return q.getResultList();
                        } finally {
                            em.close();
                        }
                    }
                
                    public TableB findTableB(TableBPK id) {
                        EntityManager em = getEntityManager();
                        try {
                            return em.find(TableB.class, id);
                        } finally {
                            em.close();
                        }
                    }
                
                    public int getTableBCount() {
                        EntityManager em = getEntityManager();
                        try {
                            Query q = em.createQuery("select count(o) from TableB as o");
                            return ((Long) q.getSingleResult()).intValue();
                        } finally {
                            em.close();
                        }
                    }
                
                }
                The exception is thrown on the second time when create of controller B is called.
                Here is the full exception description:
                Exception in thread "main" test.controllers.exceptions.PreexistingEntityException: TableB test.tables.TableB[tableBPK=test.tables.TableBPK[idTableB=0, idTableA=3]] already exists.
                        at test.controllers.TableBJpaController.create(TableBJpaController.java:57)
                        at test.Main.main(Main.java:41)
                Caused by: javax.persistence.EntityExistsException: 
                Exception Description: Cannot persist detached object [test.tables.TableB[tableBPK=test.tables.TableBPK[idTableB=0, idTableA=3]]]. 
                Class> test.tables.TableB Primary Key> [3, 0]
                        at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:208)
                        at test.controllers.TableBJpaController.create(TableBJpaController.java:49)
                        ... 1 more
                Caused by: Exception [TOPLINK-7231] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.ValidationException
                Exception Description: Cannot persist detached object [test.tables.TableB[tableBPK=test.tables.TableBPK[idTableB=0, idTableA=3]]]. 
                Class> test.tables.TableB Primary Key> [3, 0]
                        at oracle.toplink.essentials.exceptions.ValidationException.cannotPersistExistingObject(ValidationException.java:2171)
                        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:3251)
                        at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:339)
                        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3220)
                        at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:205)
                        ... 2 more
                Thanks for your help. I appreciate it alot.

                Kind Regards
                • 5. Re: Preexisting Entity Exception
                  Cdelahun-Oracle
                  Hello,

                  More code than I expected. You can probably simplify it a bit using the em.merge(entityA) instead of calling persist, trying to find each b in the collection, have it reference the managed B and then merging each B. Because the A->B relationship is marked cascade all, the merge operation will pick up new Bs as well as merge changes into existing B objects. Only difference is that merge will return a new, managed instance of A. This means that your application would need to return the managed instance, as the A passed into the create method would not have its primary key information set after the transaction. Another problem is that the method is calling tableBCollectionTableB.setTableA(tableA); This code seems like your application allows changing B's to reference different As - this is not allowed, as it changes B's id. Once an entity has its ID, they should not be updated - the only way to do that is effectively delete the entity and persist it with a new identity.

                  The problem you are encountering is that controllerB.create(tableB2) will always fail because tableB2 does not have an id that is unique from the previous tableB1 - it is not using sequencing, so every single B associated to an A will have the same id of 0 and A's id for the (idTableB, idTableA) fields. Try using sequencing, or assigning a value directly using the tableBX.getTableBPK().setIdTableB(X) method.

                  Best Regards,
                  Chris
                  • 6. Re: Preexisting Entity Exception
                    795665
                    Hi Chris

                    Sorry for the late reply.

                    >
                    The problem you are encountering is that controllerB.create(tableB2) will always fail because tableB2 does not have an id that is unique from the previous tableB1 - it is not using sequencing, so every single B associated to an A will have the same id of 0 and A's id for the (idTableB, idTableA) fields. Try using sequencing, or assigning a value directly using the tableBX.getTableBPK().setIdTableB(X) method.


                    I prefer not to set the id manually but rather use sequencing to do the id generation for me. However I don't understand why it is not using sequencing because I made both primary keys of table A and Table B auto incremental.

                    Regards
                    • 7. Re: Preexisting Entity Exception
                      795665
                      Hi

                      If I make the relationship non-identifying then I am able to persist both records without having to manually specify an id and it uses sequencing.
                      However, I prefer to use an identifying relationship.

                      Regards