public void insertCommunityPositionInfo(CommunityPositionInfo poCmtPstInf) throws ApplicationException, Exception { CommunityPositionInfoDAO voCommunityPositionInfoDAO = new CommunityPositionInfoDAO(); try { context.getUserTransaction().begin(); if (voCommunityPositionInfoDAO.validateCommunityPositionForInsert( em, poCmtPstInf.getCommunityPositionDesc()) == false) { voCommunityPositionInfoDAO.insertCommunityPositionInfo(em, poCmtPstInf); } else { String vaTmp = (String) em.createQuery( "select (o.communityPositionID) from CommunityPositionInfo o where FUNC('REPLACE', UPPER(o.communityPositionDesc), ' ', '') = FUNC('REPLACE', UPPER('" + poCmtPstInf.getCommunityPositionDesc() + "'), ' ', '')") .getSingleResult() .toString(); throw new ApplicationException( "มีรหัสตำแหน่ง <b>" + vaTmp + " - " + poCmtPstInf.getCommunityPositionDesc() + "</b> อยู่แล้ว"); } context.getUserTransaction().commit(); } catch (ApplicationException ae) { try { context.getUserTransaction().rollback(); } catch (Exception ee) { System.out.println(); } throw new ApplicationException(ae.getMessage()); } catch (Exception e) { try { context.getUserTransaction().rollback(); } catch (Exception ee) { System.out.println(); } throw new Exception( new StringBuffer("CommunityPositionInfoEJBServBean.insertCommunityPositionInfo : ") .append(e.getMessage()) .toString()); } }