use of javax.persistence.EntityNotFoundException in project spring-framework by spring-projects.
the class EntityManagerFactoryUtilsTests method testConvertJpaPersistenceException.
/*
* Test method for
* 'org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessException(PersistenceException)'
*/
@Test
@SuppressWarnings("serial")
public void testConvertJpaPersistenceException() {
EntityNotFoundException entityNotFound = new EntityNotFoundException();
assertSame(JpaObjectRetrievalFailureException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityNotFound).getClass());
NoResultException noResult = new NoResultException();
assertSame(EmptyResultDataAccessException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(noResult).getClass());
NonUniqueResultException nonUniqueResult = new NonUniqueResultException();
assertSame(IncorrectResultSizeDataAccessException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(nonUniqueResult).getClass());
OptimisticLockException optimisticLock = new OptimisticLockException();
assertSame(JpaOptimisticLockingFailureException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(optimisticLock).getClass());
EntityExistsException entityExists = new EntityExistsException("foo");
assertSame(DataIntegrityViolationException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityExists).getClass());
TransactionRequiredException transactionRequired = new TransactionRequiredException("foo");
assertSame(InvalidDataAccessApiUsageException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(transactionRequired).getClass());
PersistenceException unknown = new PersistenceException() {
};
assertSame(JpaSystemException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(unknown).getClass());
}
use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.
the class TblMleJpaController method destroy.
public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
TblMle tblMle;
try {
tblMle = em.getReference(TblMle.class, id);
tblMle.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The tblMle with id " + id + " no longer exists.", enfe);
}
List<String> illegalOrphanMessages = null;
Collection<TblHosts> tblHostsCollectionOrphanCheck = tblMle.getTblHostsCollection();
for (TblHosts tblHostsCollectionOrphanCheckTblHosts : tblHostsCollectionOrphanCheck) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblHosts " + tblHostsCollectionOrphanCheckTblHosts + " in its tblHostsCollection field has a non-nullable vmmMleId field.");
}
Collection<TblHosts> tblHostsCollection1OrphanCheck = tblMle.getTblHostsCollection1();
for (TblHosts tblHostsCollection1OrphanCheckTblHosts : tblHostsCollection1OrphanCheck) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblHosts " + tblHostsCollection1OrphanCheckTblHosts + " in its tblHostsCollection1 field has a non-nullable biosMleId field.");
}
Collection<TblPcrManifest> tblPcrManifestCollectionOrphanCheck = tblMle.getTblPcrManifestCollection();
for (TblPcrManifest tblPcrManifestCollectionOrphanCheckTblPcrManifest : tblPcrManifestCollectionOrphanCheck) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblPcrManifest " + tblPcrManifestCollectionOrphanCheckTblPcrManifest + " in its tblPcrManifestCollection field has a non-nullable mleId field.");
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
em.remove(tblMle);
em.getTransaction().commit();
} finally {
em.close();
}
}
use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.
the class MwMleSourceJpaController method destroy.
public void destroy(Integer id) throws NonexistentEntityException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
MwMleSource mwMleSource;
try {
mwMleSource = em.getReference(MwMleSource.class, id);
mwMleSource.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The mwMleSource with id " + id + " no longer exists.", enfe);
}
TblMle mleId = mwMleSource.getMleId();
if (mleId != null) {
mleId.getMwMleSourceCollection().remove(mwMleSource);
em.merge(mleId);
}
em.remove(mwMleSource);
em.getTransaction().commit();
} finally {
em.close();
}
}
use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.
the class TblHostSpecificManifestJpaController method destroy.
public void destroy(Integer id) throws NonexistentEntityException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
TblHostSpecificManifest tblHostSpecificManifest;
try {
tblHostSpecificManifest = em.getReference(TblHostSpecificManifest.class, id);
tblHostSpecificManifest.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The tblHostSpecificManifest with id " + id + " no longer exists.", enfe);
}
TblModuleManifest moduleManifestID = tblHostSpecificManifest.getModuleManifestID();
if (moduleManifestID != null) {
moduleManifestID.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifest);
em.merge(moduleManifestID);
}
em.remove(tblHostSpecificManifest);
em.getTransaction().commit();
} finally {
em.close();
}
}
use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.
the class MwKeystoreJpaController method destroy.
public void destroy(Integer id) throws NonexistentEntityException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
MwKeystore mwKeystore;
try {
mwKeystore = em.getReference(MwKeystore.class, id);
mwKeystore.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The mwKeystore with id " + id + " no longer exists.", enfe);
}
em.remove(mwKeystore);
em.getTransaction().commit();
} finally {
em.close();
}
}
Aggregations