private void insertRecordInJoinTable ( String schemaName , String joinTableName , String joinColumnName , String inverseJoinColumnName , Object parentId , Set < Object > childrenIds ) { s = getStatelessSession ( ) ; Transaction tx = onBegin ( ) ; for ( Object childId : childrenIds ) { StringBuffer query = new StringBuffer ( ) ; // write an update query Object [ ] existingRowIds = findIdsByColumn ( schemaName , joinTableName , joinColumnName , inverseJoinColumnName , ( String ) childId , null ) ; boolean joinTableRecordsExists = false ; if ( existingRowIds != null && existingRowIds . length > 0 ) { for ( Object o : existingRowIds ) { if ( o . toString ( ) . equals ( parentId . toString ( ) ) ) { joinTableRecordsExists = true ; break ; } } } if ( ! joinTableRecordsExists ) { query . append ( "INSERT INTO " ) . append ( getFromClause ( schemaName , joinTableName ) ) . append ( "(" ) . append ( joinColumnName ) . append ( "," ) . append ( inverseJoinColumnName ) . append ( ")" ) . append ( " VALUES('" ) . append ( parentId ) . append ( "','" ) . append ( childId ) . append ( "')" ) ; s . createSQLQuery ( query . toString ( ) ) . executeUpdate ( ) ; } } onCommit ( tx ) ; // tx.commit(); }
Insert record in join table .