Session tmpSession = null;
Transaction tx = null;
try {
tmpSession = getSession();
tx = tmpSession.beginTransaction();
SbiMenu hibMenu = new SbiMenu();
hibMenu.setName(aMenu.getName());
hibMenu.setDescr(aMenu.getDescr());
hibMenu.setParentId(aMenu.getParentId());
hibMenu.setObjId(aMenu.getObjId());
hibMenu.setObjParameters(aMenu.getObjParameters());
hibMenu.setSubObjName(aMenu.getSubObjName());
hibMenu.setSnapshotName(aMenu.getSnapshotName());
hibMenu.setSnapshotHistory(aMenu.getSnapshotHistory());
hibMenu.setFunctionality(aMenu.getFunctionality());
hibMenu.setInitialPath(aMenu.getInitialPath());
hibMenu.setViewIcons(new Boolean(aMenu.isViewIcons()));
hibMenu.setHideToolbar(new Boolean(aMenu.getHideToolbar()));
hibMenu.setHideSliders(new Boolean(aMenu.getHideSliders()));
hibMenu.setStaticPage(aMenu.getStaticPage());
hibMenu.setExternalApplicationUrl(aMenu.getExternalApplicationUrl());
// manages prog column that determines the menu order
Query hibQuery = null;
if (aMenu.getParentId() == null || aMenu.getParentId().intValue()==0 ) //hibMenu.setProg(new Integer(1));
hibQuery = tmpSession.createQuery("select max(s.prog) from SbiMenu s where s.parentId is null ");
else {
// loads sub menu
//hibQuery = tmpSession.createQuery("select max(s.prog) from SbiMenu s where s.parentId = " + aMenu.getParentId());
hibQuery = tmpSession.createQuery("select max(s.prog) from SbiMenu s where s.parentId = ?" );
hibQuery.setInteger(0, aMenu.getParentId().intValue());
}
Integer maxProg = (Integer) hibQuery.uniqueResult();
if (maxProg != null) hibMenu.setProg(new Integer(maxProg.intValue() + 1));
else hibMenu.setProg(new Integer(1));
updateSbiCommonInfo4Insert(hibMenu);
tmpSession.save(hibMenu);
Set menuRoleToSave = new HashSet();
Set temp=saveRolesMenu(tmpSession, hibMenu,
aMenu);
menuRoleToSave.addAll(temp);
// set new roles into sbiFunctions
hibMenu.setSbiMenuRoles(menuRoleToSave);
tx.commit();
} catch (HibernateException he) {
logException(he);