Hi, I have 2 tables named T1 and T2. Where T1 is parent and T2 is child. The scenario is, I started a jdbc transaction and then insert a row in T1 and then try to insert a row in T2. Inserting row in T2 gies me "Integrity Constraint-Parent key not found" exception.
How i handle this scenario ?
Connection con;
try{
con = ConnectionPool.getConnection();
con.setAutoCommit(false);
int T1Id = getNewId("T1"); // from sequence;
int T2Id = getNewId("T2"); // from sequence;
Insert in to table T1(t1Id,tName) values (T1Id,'A')
Insert in to table T2(t2Id, t1Id,tName) values (T2Id,T1Id,'A')//Here, Exception raises
con.commit();
}catch(Exception e){
try {con.rollback();} catch (SQLException e) {}
}finally{
try {con.setAutoCommit(true);} catch (SQLException e) {}
ConnectionPool.returnConnection(con);
}
Using JDBC API, struts1.2, Oracle10 G Database