Example usage for javax.persistence PersistenceException getMessage

List of usage examples for javax.persistence PersistenceException getMessage

Introduction

In this page you can find the example usage for javax.persistence PersistenceException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.finra.dm.service.BusinessObjectDataServiceCreateBusinessObjectDataTest.java

@Test
public void testCreateBusinessObjectDataDuplicateParentsBypassingDuplicateParentCheck() {
    // This will create a business object data create request with parents.
    BusinessObjectDataCreateRequest businessObjectDataCreateRequest = getNewBusinessObjectDataCreateRequest(
            true);/* www  .ja v  a2 s.c  om*/

    // Add a duplicate parent that has no namespace specified.
    List<BusinessObjectDataKey> businessObjectDataKeys = businessObjectDataCreateRequest
            .getBusinessObjectDataParents();
    BusinessObjectDataKey duplicateParentKey = businessObjectDataHelper
            .cloneToLowerCase(businessObjectDataKeys.get(0));
    duplicateParentKey.setNamespace(null);
    businessObjectDataKeys.add(duplicateParentKey);

    // Try to create a business object data with duplicate parents.
    try {
        businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest);
        fail("Should throw a PersistenceException when business object data create request contains duplicate parents.");
    } catch (PersistenceException e) {
        assertEquals("org.hibernate.exception.ConstraintViolationException: could not execute statement",
                e.getMessage());
    }
}

From source file:org.finra.herd.service.BusinessObjectFormatServiceTest.java

@Test
public void testCreateBusinessObjectFormatIncorrectLatestVersion() throws Exception {
    // Create relative database entities.
    businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting();

    // Create a first version of the format with the latest flag set to false.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE,
            FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA,
            FORMAT_DOCUMENT_SCHEMA_URL, false, PARTITION_KEY);

    try {/*from w ww .  ja v  a 2s  .co m*/
        // Try to create a new format version for this format.
        final BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = businessObjectFormatServiceTestHelper
                .createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE,
                        FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA,
                        FORMAT_DOCUMENT_SCHEMA_URL,
                        businessObjectDefinitionServiceTestHelper.getNewAttributes(),
                        businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(),
                        businessObjectFormatServiceTestHelper.getTestSchema());
        executeWithoutLogging(SqlExceptionHelper.class, new Command() {
            @Override
            public void execute() {
                businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
                fail("Should throw a PersistenceException since the latest flag does not identify the maximum format version.");
            }
        });
    } catch (PersistenceException e) {
        assertTrue(e.getMessage().contains("ConstraintViolationException: could not execute"));
    }
}

From source file:org.hoteia.qalingo.core.service.impl.WebBackofficeServiceImpl.java

public void createCatalogCategory(final MarketArea currentMarketArea, final Localization currentLocalization,
        final CatalogCategoryMaster parentCatalogCategory, final CatalogCategoryMaster catalogCategory,
        final CatalogCategoryForm catalogCategoryForm) throws UniqueConstraintCodeCategoryException {
    String catalogCategoryCode = catalogCategoryForm.getCode();
    catalogCategory.setBusinessName(catalogCategoryForm.getName());
    catalogCategory.setCode(catalogCategoryForm.getCode());
    catalogCategory.setDescription(catalogCategoryForm.getDescription());
    catalogCategory.setDefaultParentCatalogCategory(parentCatalogCategory);

    if (catalogCategoryForm != null && catalogCategoryForm.getMarketAreaAttributes() != null) {
        Map<String, String> attributes = catalogCategoryForm.getMarketAreaAttributes();
        for (Iterator<String> iterator = attributes.keySet().iterator(); iterator.hasNext();) {
            String attributeKey = (String) iterator.next();
            String value = attributes.get(attributeKey);
            if (StringUtils.isNotEmpty(value)) {
                catalogCategory.getCatalogCategoryMarketAreaAttributes(currentMarketArea.getId())
                        .add(buildCatalogCategoryMasterAttribute(currentMarketArea, currentLocalization,
                                attributeKey, value, false));
            }/*from w  w w .  j a  v  a2s .co m*/
        }
    }

    if (catalogCategoryForm != null && catalogCategoryForm.getGlobalAttributes() != null) {
        Map<String, String> attributes = catalogCategoryForm.getGlobalAttributes();
        for (Iterator<String> iterator = attributes.keySet().iterator(); iterator.hasNext();) {
            String attributeKey = (String) iterator.next();
            String value = attributes.get(attributeKey);
            if (StringUtils.isNotEmpty(value)) {
                catalogCategory.getCatalogCategoryMarketAreaAttributes(currentMarketArea.getId())
                        .add(buildCatalogCategoryMasterAttribute(currentMarketArea, currentLocalization,
                                attributeKey, value, true));
            }
        }
    }

    try {
        catalogCategoryService.saveOrUpdateCatalogCategory(catalogCategory);

        if (parentCatalogCategory != null) {
            if (!parentCatalogCategory.getCatalogCategories().contains(catalogCategory)) {
                // PARENT DOESN'T CONTAIN THE NEW CATEGORY - ADD IT IN THE MANY TO MANY
                CatalogCategoryMaster reloadedCatalogCategory = catalogCategoryService
                        .getMasterCatalogCategoryByCode(catalogCategoryCode);
                parentCatalogCategory.getCatalogCategories().add(reloadedCatalogCategory);
                catalogCategoryService.saveOrUpdateCatalogCategory(parentCatalogCategory);
            }
        }

    } catch (PersistenceException e) {
        if (e.getMessage().contains("ConstraintViolationException")) {
            throw new UniqueConstraintCodeCategoryException();
        } else {
            throw new UniqueConstraintCodeCategoryException();
        }
    }

}

From source file:org.opens.urlmanager.inhibitor.AEPersistenceInhibitor.java

public void inhibitPersistenceException(PersistenceException e) {
    LogFactory.getLog(AEPersistenceInhibitor.class).debug("Inhibiting persistence exception", e);
    if (e.getCause() instanceof ConstraintViolationException) {
        // TODO : create the appropriate exception with its appropriate HTTP error code
        throw new InternalErrorException("Constraint violation exception", e);
    } else if (e.getCause() instanceof SQLGrammarException) {
        throw new InternalErrorException("SQL grammar error", e);
    } else {//from  w  w  w .  j a va2s .c o  m
        throw new InternalErrorException("Persistence error : " + e.getMessage(), e);
    }
}

From source file:org.rhq.enterprise.server.measurement.MeasurementDefinitionManagerBean.java

/**
 * Remove the given definition with its attached schedules.
 *
 * @param def the MeasuremendDefinition to delete
 */// www  .j a  v a 2s.  c o m
public void removeMeasurementDefinition(MeasurementDefinition def) {
    // First remove the schedules and associated OOBs.
    List<MeasurementSchedule> schedules = def.getSchedules();
    Iterator<MeasurementSchedule> schedIter = schedules.iterator();
    while (schedIter.hasNext()) {
        MeasurementSchedule sched = schedIter.next();
        if (sched.getBaseline() != null) {
            entityManager.remove(sched.getBaseline());
            sched.setBaseline(null);
        }
        oobManager.removeOOBsForSchedule(subjectManager.getOverlord(), sched);
        sched.getResource().setAgentSynchronizationNeeded();
        entityManager.remove(sched);
        schedIter.remove();
    }

    // Now remove the definition itself.
    try {
        if ((def.getId() != 0) && entityManager.contains(def)) {
            entityManager.remove(def);
        }
    } catch (EntityNotFoundException enfe) {
        if (log.isDebugEnabled()) {
            log.debug("Definition # " + def.getId() + " not found: " + enfe.getMessage());
        }
    } catch (PersistenceException pe) {
        if (log.isDebugEnabled()) {
            log.debug("Exception when deleting Definition # " + def.getId() + ": " + pe.getMessage());
        }
    } catch (Exception e) {
        log.warn(e.fillInStackTrace());
    }
}

From source file:org.viafirma.persistencia.dao.GenericEjb3Dao.java

/**
 * Persiste la entidad indicada//w ww . java2s. com
 * @throws ExcepcionNoCreado 
 */
public T create(T entidad) throws ExcepcionNoCreado {
    EntityManager manager = getEntityManager();
    try {
        manager.getTransaction().begin();
        log.config("Creando " + entidad);
        manager.persist(entidad);
        manager.getTransaction().commit();
        return entidad;
    } catch (PersistenceException e) {
        manager.getTransaction().rollback();
        log.severe("Error al crear entidad" + e.getMessage());
        throw new ExcepcionNoCreado(e.getMessage());
    } finally {
        manager.close();
    }
}

From source file:se.nrm.dina.manager.dao.AccountDao.java

public TblUsers createAccount(TblUsers user) {
    logger.info("createAccount: {}", user);
    TblUsers tmp = user;//from w w w.j  a 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;
}