0 Replies Latest reply on Sep 21, 2016 1:22 PM by sabbirali kadiwala

    JPA + @ManytoOne unidirection foreign key parent key not found

    sabbirali kadiwala Newbie

      Hi Team,

       

      I have two table one is master table and second table is reference table

       

      table 1 - create new row in this table this will generate new sequence no lets say : r_id

       

      table 2 - it has few row and we need to update row in this table with r_id

       

      Class Table1

      @SequenceGenerator(name="SEQ_MAP_GEN",sequenceName="SEQ_id", allocationSize=1,initialValue=1)

      public class Table1 implements Serializable{

        private static final long serialVersionUID = 1L;

        @Id

        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_MAP_GEN")

        @Column(name="R_ID")

        private Long rId;

      ---------

       

      Class Table2

       

      @ManyToOne(fetch=Fe-tchType.LAZY)

      @JoinColumn(name = "R_ID")

      private Table1 table1;

       

      problem :

       

      when i insert into table1 : it will generate new sequence and i need to update same in to table2. but i got below error...

       

      Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (SYS_C0014850) violated - parent key not found

       

       

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)

        at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)

        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)

        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)

        at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)

        at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)

        at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008)

        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)

        at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)

        at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3530)

        at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)

        at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)

        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]

        ... 259 more

       

      Please help me... how to resolve it... I am using EJB with JPA as hibernate ....and wildfly 8.1 final as deployment...