Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
SbiOrgUnit hibOU = new SbiOrgUnit();
hibOU.setLabel(ou.getLabel());
hibOU.setName(ou.getName());
hibOU.setDescription(ou.getDescription());
//look for preexisting one with same same label-name key
Query hibQuery = aSession.createQuery(" from SbiOrgUnit s where s.name = ? and s.label = ?");
hibQuery.setString(0, ou.getName());
hibQuery.setString(1, ou.getLabel());
SbiOrgUnit exists= (SbiOrgUnit)hibQuery.uniqueResult();
updateSbiCommonInfo4Insert(hibOU);
if(exists == null){
aSession.save(hibOU);
tx.commit();
ou.setId(hibOU.getId());
}else{
ou.setId(exists.getId());
tx.commit();
}
} finally {
rollbackIfActiveAndClose(tx, aSession);