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:fr.hoteia.qalingo.web.service.impl.WebBackofficeServiceImpl.java

public void createProductCategory(final MarketArea currentMarketArea, final Localization currentLocalization,
        final CatalogCategoryMaster parentProductCategory, final CatalogCategoryMaster productCategory,
        final ProductCategoryForm productCategoryForm) throws UniqueConstraintCodeCategoryException {
    String productCategoryCode = productCategoryForm.getCode();
    productCategory.setBusinessName(productCategoryForm.getName());
    productCategory.setCode(productCategoryForm.getCode());
    productCategory.setDescription(productCategoryForm.getDescription());
    productCategory.setDefaultParentCatalogCategory(parentProductCategory);

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

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

    try {
        productCategoryService.saveOrUpdateCatalogCategory(productCategory);

        if (parentProductCategory != null) {
            if (!parentProductCategory.getCatalogCategories().contains(productCategory)) {
                // PARENT DOESN'T CONTAIN THE NEW CATEGORY - ADD IT IN THE MANY TO MANY
                CatalogCategoryMaster reloadedProductCategory = productCategoryService
                        .getMasterCatalogCategoryByCode(productCategoryCode);
                parentProductCategory.getCatalogCategories().add(reloadedProductCategory);
                productCategoryService.saveOrUpdateCatalogCategory(parentProductCategory);
            }
        }

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

}

From source file:com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking.java

private void processApplicationVersionFromParameters(Application app, ApplicationVersion version,
        List<ProcessingEvent> events, Map<Object, Object> parameterMap) {

    // a version is not being modified,
    // then create a new archive for it.
    if (version.getPk() == null) {
        version.setArchive(new ApplicationArchive());
        version.getArchive().setApplication(app);
        version.setApplication(app);/*from   ww w .  j a  v a 2s  . c  om*/
    }

    fillInApplicationVersionFromParameters(app, version, events, parameterMap);

    if (version != null && version.getArchive() == null) {
        events.add(new MessagesEvent("Application archive could not be created.  Not creating empty version."));
    } else {
        try {
            modelManager.begin();
            version.setLastModifier(firstValue("userPrincipalName", parameterMap));

            ApplicationArchive savedArchive = version.getArchive();
            version.setArchive(null);
            savedArchive = modelManager.addModify(savedArchive, events);
            version.setArchive(savedArchive);

            version = modelManager.addModify(version, events);
            app.addVersion(version);
            app = modelManager.addModify(app, events);

            modelManager.commit(events);

            modelManager.refresh(app, events);

            events.add(new MessagesEvent("Application version successfully created/modified!"));
        } catch (InvalidPropertiesException ipe) {
            modelManager.rollback();
            logger.error("Unable to add/modify version " + version.getIdentifier(), ipe);
            events.add(new MessagesEvent("Unable to add/modify version - " + ipe.getMessage()));
        } catch (PersistenceException pe) {
            modelManager.rollback();
            logger.error("Unable to add/modify version " + version.getIdentifier(), pe);
            events.add(new MessagesEvent("Unable to add/modify version - " + pe.getMessage()));
        }
    }
}

From source file:com.impetus.kundera.metadata.MetadataManager.java

/**
 * Helper class to scan each @Entity class and build various relational annotation.
 * //from  w  w w.j a  va2s .  c  o  m
 * @param entity
 *            the entity
 */
private void processRelations(Class<?> entity) {
    EntityMetadata metadata = getEntityMetadata(entity);

    for (Field f : entity.getDeclaredFields()) {

        // OneToOne
        if (f.isAnnotationPresent(OneToOne.class)) {
            // taking field's type as foreign entity, ignoring
            // "targetEntity"
            Class<?> targetEntity = f.getType();
            try {
                validate(targetEntity);
                OneToOne ann = f.getAnnotation(OneToOne.class);

                Relation relation = metadata.new Relation(f, targetEntity, null, ann.fetch(),
                        Arrays.asList(ann.cascade()), ann.optional(), ann.mappedBy(),
                        EntityMetadata.ForeignKey.ONE_TO_ONE);

                metadata.addRelation(f.getName(), relation);
            } catch (PersistenceException pe) {
                throw new PersistenceException("Error with @OneToOne in @Entity(" + entity.getName() + "."
                        + f.getName() + "), reason: " + pe.getMessage());
            }
        }

        // OneToMany
        else if (f.isAnnotationPresent(OneToMany.class)) {

            OneToMany ann = f.getAnnotation(OneToMany.class);

            Class<?> targetEntity = null;

            // resolve from generic parameters
            Type[] parameters = ReflectUtils.getTypeArguments(f);
            if (parameters != null) {
                if (parameters.length == 1) {
                    targetEntity = (Class<?>) parameters[0];
                } else {
                    throw new PersistenceException("How many parameters man?");
                }
            }
            // now, check annotations
            if (null != ann.targetEntity() && !ann.targetEntity().getSimpleName().equals("void")) {
                targetEntity = ann.targetEntity();
            }

            try {
                validate(targetEntity);
                Relation relation = metadata.new Relation(f, targetEntity, f.getType(), ann.fetch(),
                        Arrays.asList(ann.cascade()), Boolean.TRUE, ann.mappedBy(),
                        EntityMetadata.ForeignKey.ONE_TO_MANY);

                metadata.addRelation(f.getName(), relation);
            } catch (PersistenceException pe) {
                throw new PersistenceException("Error with @OneToMany in @Entity(" + entity.getName() + "."
                        + f.getName() + "), reason: " + pe.getMessage());
            }
        }

        // ManyToOne
        else if (f.isAnnotationPresent(ManyToOne.class)) {
            // taking field's type as foreign entity, ignoring
            // "targetEntity"
            Class<?> targetEntity = f.getType();
            try {
                validate(targetEntity);
                ManyToOne ann = f.getAnnotation(ManyToOne.class);

                Relation relation = metadata.new Relation(f, targetEntity, null, ann.fetch(),
                        Arrays.asList(ann.cascade()), ann.optional(), null, // mappedBy is null
                        EntityMetadata.ForeignKey.MANY_TO_ONE);

                metadata.addRelation(f.getName(), relation);
            } catch (PersistenceException pe) {
                throw new PersistenceException("Error with @OneToOne in @Entity(" + entity.getName() + "."
                        + f.getName() + "), reason: " + pe.getMessage());
            }
        }

        // ManyToMany
        else if (f.isAnnotationPresent(ManyToMany.class)) {

            ManyToMany ann = f.getAnnotation(ManyToMany.class);

            Class<?> targetEntity = null;

            // resolve from generic parameters
            Type[] parameters = ReflectUtils.getTypeArguments(f);
            if (parameters != null) {
                if (parameters.length == 1) {
                    targetEntity = (Class<?>) parameters[0];
                } else {
                    throw new PersistenceException("How many parameters man?");
                }
            }
            // now, check annotations
            if (null != ann.targetEntity() && !ann.targetEntity().getSimpleName().equals("void")) {
                targetEntity = ann.targetEntity();
            }

            try {
                validate(targetEntity);
                Relation relation = metadata.new Relation(f, targetEntity, f.getType(), ann.fetch(),
                        Arrays.asList(ann.cascade()), Boolean.TRUE, ann.mappedBy(),
                        EntityMetadata.ForeignKey.MANY_TO_MANY);

                metadata.addRelation(f.getName(), relation);
            } catch (PersistenceException pe) {
                throw new PersistenceException("Error with @OneToMany in @Entity(" + entity.getName() + "."
                        + f.getName() + "), reason: " + pe.getMessage());
            }
        }

    }
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<HotelInfo> getAllHotelInfo() {
    List<HotelInfo> hotelInfos = new ArrayList<HotelInfo>();

    try {/*from w w w .j  a v  a2 s  . c  om*/
        hotelInfos = getEm().createQuery("select o.hotelCode from HotelInfo o order by o.id").getResultList();
        ;
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelInfos;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<String> getAllHotelCodes() {
    List<String> hotelCodes = new ArrayList<String>();

    try {/*from w ww .jav a  2s.com*/
        //body
        hotelCodes = getEm().createQuery("select o.hotelCode from HotelInfo o order by o.id").getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelCodes;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public CacheCity getCacheCity(int cityId) {
    List<CacheCity> cacheCities = new ArrayList<CacheCity>();

    try {/* ww  w.  j a  va2  s.c  om*/
        //body
        cacheCities = getEm().createQuery("select o from CacheCity o where o.cityId = :cityId")
                .setParameter("cityId", cityId).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return cacheCities.size() > 0 ? cacheCities.get(0) : null;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public CacheHotel getCacheHotel(String hotelCode) {
    List<CacheHotel> cacheHotels = new ArrayList<CacheHotel>();

    try {/*  w w w. j ava 2s  .c o  m*/
        //body
        cacheHotels = getEm().createQuery("select o from CacheHotel o where o.hotelCode = :hotelCode")
                .setParameter("hotelCode", hotelCode).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return cacheHotels.size() > 0 ? cacheHotels.get(0) : null;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<District> getDistrictByCityId(int cityId) {
    List<District> districts = null;

    try {// www  .  ja v a 2  s  .co  m
        //body
        districts = getEm().createQuery("select o from District o where o.cityId = :cityId")
                .setParameter("cityId", cityId).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return districts;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<Zone> getZoneByCityId(int cityId) {
    List<Zone> zones = null;

    try {//from w  w  w .j av a 2  s. co  m
        //body
        zones = getEm().createQuery("select o from Zone o where o.cityId = :cityId")
                .setParameter("cityId", cityId).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return zones;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public HotelGuestRoom getHotelRoomInfo(int hotelId, String roomTypeCode) {
    List<HotelGuestRoom> rooms = null;

    try {/*from   www  .j a va 2 s. co m*/
        //body
        rooms = getEm().createQuery(
                "select o from HotelGuestRoom o left join fetch o.hotelGuestRoomAmenities where o.hotelInfo.id = :hotelId and o.roomTypeCode = :roomTypeCode")
                .setParameter("hotelId", hotelId).setParameter("roomTypeCode", roomTypeCode).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return rooms.size() > 0 ? rooms.get(0) : null;
}