List of usage examples for javax.persistence PersistenceException getCause
public synchronized Throwable getCause()
From source file:org.tinymediamanager.core.TmmModuleManager.java
/** * start up tmm - do initialization code here *//* ww w .j a v a2 s .c o m*/ public void startUp() { // enhance if needed if (System.getProperty("tmmenhancer") != null) { // changed enhancer to be in sync with the build.xml com.objectdb.Enhancer.enhance("-s org.tinymediamanager.core.*"); // com.objectdb.Enhancer.enhance("org.tinymediamanager.core.entities.*"); // com.objectdb.Enhancer.enhance("org.tinymediamanager.core.movie.entities.*"); // com.objectdb.Enhancer.enhance("org.tinymediamanager.core.tvshow.entities.*"); // com.objectdb.Enhancer.enhance("org.tinymediamanager.scraper.MediaTrailer"); } // get a connection to the database EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(TMM_DB); try { entityManager = entityManagerFactory.createEntityManager(); } catch (PersistenceException e) { if (e.getCause().getMessage().contains("does not match db file")) { // happens when there's a recovery file which does not match (cannot be recovered) - just delete and try again FileUtils.deleteQuietly(new File(TMM_DB + "$")); entityManager = entityManagerFactory.createEntityManager(); } else { // unknown throw (e); } } }
From source file:org.zanata.action.UserAction.java
@Transactional public void deleteUser(String userName) { try {/*from w w w. j ava 2s. c om*/ identityManager.deleteUser(userName); // NB: Need to call flush here to be able to catch the persistence // exception, otherwise it would be caught by Seam. accountDAO.flush(); userFilter.reset(); } catch (PersistenceException e) { if (e.getCause() instanceof ConstraintViolationException) { facesMessages.addFromResourceBundle(SEVERITY_ERROR, "jsf.UserManager.delete.constraintViolation.error"); } } }
From source file:se.nrm.dina.data.jpa.DinaDaoImpl.java
@Override public T create(T entity) { logger.info("create(T) : {}", entity); T tmp = entity;/*from w w w .ja v a 2s . c o m*/ try { entityManager.persist(entity); entityManager.flush(); logger.info("temp : {}", tmp); } catch (javax.persistence.PersistenceException ex) { if (ex.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { org.hibernate.exception.ConstraintViolationException e = (org.hibernate.exception.ConstraintViolationException) ex .getCause(); throw new DinaConstraintViolationException( handleHibernateConstraintViolation(e, entity.getClass().getSimpleName()), 400); } } catch (ConstraintViolationException e) { throw new DinaConstraintViolationException(handleConstraintViolations(e), 400); } catch (Exception e) { } return tmp; }
From source file:se.nrm.dina.data.jpa.impl.DinaDaoImpl.java
@Override public T create(T entity) { logger.info("create(T) : {}", entity); T tmp = entity;//from w w w . j a v a2s . c o m try { entityManager.persist(entity); entityManager.flush(); } catch (javax.persistence.PersistenceException ex) { if (ex.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { org.hibernate.exception.ConstraintViolationException e = (org.hibernate.exception.ConstraintViolationException) ex .getCause(); throw new DinaConstraintViolationException( handleHibernateConstraintViolation(e, entity.getClass().getSimpleName()), 400); } } catch (ConstraintViolationException e) { throw new DinaConstraintViolationException(handleConstraintViolations(e), 400); } catch (Exception e) { throw new DinaException(e.getMessage(), 400); } return tmp; }
From source file:se.nrm.dina.manager.dao.AccountDao.java
public TblUsers createAccount(TblUsers user) { logger.info("createAccount: {}", user); TblUsers tmp = user;/*w ww . ja v a 2 s . co m*/ try { entityManager.persist(user); entityManager.flush(); } catch (ConstraintViolationException e) { logger.error(e.getMessage()); } catch (javax.persistence.PersistenceException ex) { logger.error("PersistenceException : {}", ex.getMessage()); if (ex.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { org.hibernate.exception.ConstraintViolationException e = (org.hibernate.exception.ConstraintViolationException) ex .getCause(); throw new ManagerException(handleHibernateConstraintViolation(e), 400); } } catch (Exception e) { logger.error(e.getMessage()); } return tmp; }