Hi, I have a below relationship between entities
@Table(name = "Table1") @SecondaryTable(name = "Table2", pkJoinColumns = @PrimaryKeyJoinColumn(name = "Table1_ID")) @Entity public class Table1DO{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "Table1_ID") private Long table1PrmryKey; @OneToOne @JoinColumn(name = "Table1_ID", referencedColumnName = "Table1_ID") private Table2 table2DO; //other attributes and it's accessor methods } @Table(name = "Table2") @Entity public class Table2DO{ @Id @Column(name = "Table1_ID") private Long table2ID; } When we persist Table1, it fails saying Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Cannot insert explicit value for identity column in table 'Table1' when IDENTITY_INSERT is set to OFF. {prepstmnt 73139292 INSERT INTO Table1 (Table1_ID, ............) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?]} [code=544, state=S0001] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:273) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:249) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$1000(LoggingConnectionDecorator.java:70) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1095) at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:285) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1702) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:267) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:118) ... 127 more NestedThrowables: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 fatal store error> org.apache.openjpa.persistence.EntityExistsException: Cannot insert the value NULL into column 'Table1_ID', table "Table2"; column does not allow nulls. INSERT fails. {prepstmnt 1844866550 INSERT INTO Table2(Table1_ID, ............) VALUES (?, ?, ?, ?, ?, ?) [params=?, ?, ?, ?, ?, ?]} [code=515, state=23000] We want to first insert values into table1 so that value of primary key(table1_Id) can be assigned to table2.table1_id column. how to achieve that? Thanks unmarshall -- View this message in context: http://openjpa.208410.n2.nabble.com/Failing-while-inserting-row-into-db-table-tp6848586p6848586.html Sent from the OpenJPA Users mailing list archive at Nabble.com.