List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(Throwable cause)
From source file:com.medigy.persist.model.data.EntitySeedDataPopulator.java
License:Open Source License
protected void populateCachedReferenceEntities(final Class entityClass, final CachedReferenceEntity[] cachedEntities, final String[] propertyList, final Object[][] data) throws HibernateException { try {/*from w ww .j a v a 2s. c o m*/ final Hashtable pdsByName = new Hashtable(); final BeanInfo beanInfo = Introspector.getBeanInfo(entityClass); final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); for (int i = 0; i < descriptors.length; i++) { final PropertyDescriptor descriptor = descriptors[i]; if (descriptor.getWriteMethod() != null) pdsByName.put(descriptor.getName(), descriptor.getWriteMethod()); } Map entityMapByCache = new HashMap<CachedReferenceEntity, Object>(); for (int i = 0; i < data.length; i++) { final Object entityObject = entityClass.newInstance(); for (int j = 0; j < propertyList.length; j++) { final Method setter = (Method) pdsByName.get(propertyList[j]); if (setter != null && data[i][j] != null) { setter.invoke(entityObject, new Object[] { data[i][j] }); } } entityMapByCache.put(cachedEntities[i], entityObject); if (!useEjb) session.save(entityObject); else entityManager.persist(entityObject); cachedEntities[i].setEntity((ReferenceEntity) entityObject); } } catch (Exception e) { log.error(e); throw new HibernateException(e); } }
From source file:com.medigy.persist.util.HibernateConfiguration.java
License:Open Source License
public void registerReferenceEntitiesAndCaches() { final Iterator classMappings = getClassMappings(); while (classMappings.hasNext()) { Class aClass = ((PersistentClass) classMappings.next()).getMappedClass(); //(Class) classMappings.next(); if (ReferenceEntity.class.isAssignableFrom(aClass)) { boolean foundCache = false; for (final Class ic : aClass.getClasses()) { if (CachedReferenceEntity.class.isAssignableFrom(ic)) { if (ic.isEnum()) { referenceEntitiesAndCachesMap.put(aClass, ic); foundCache = true; } else throw new HibernateException(ic + " must be an enum since " + aClass + " is a " + ReferenceEntity.class.getName()); break; }/* ww w . ja v a 2 s .c o m*/ } if (!foundCache) log.warn(aClass + " is marked as a ReferenceEntity but does not contain a ReferenceEntityCache enum."); // TODO: find out how to ensure the new mapping for reference type is immutable and read only // final PersistentClass pClass = getClassMapping(aClass.getLabel()); } else if (CustomReferenceEntity.class.isAssignableFrom(aClass)) { for (final Class ic : aClass.getClasses()) { if (CachedCustomReferenceEntity.class.isAssignableFrom(ic)) { if (ic.isEnum()) { customReferenceEntitiesAndCachesMap.put(aClass, ic); } else throw new HibernateException(ic + " must be an enum since " + aClass + " is a " + CachedCustomReferenceEntity.class.getName()); break; } } // if no cache is found, its ok since these are custom } } }
From source file:com.medigy.persist.util.HibernateUtil.java
License:Open Source License
protected static Map<Class, Class<? extends CachedReferenceEntity>> getReferenceEntitiesAndRespectiveEnums( final Iterator classMappings) { Map<Class, Class<? extends CachedReferenceEntity>> referenceEntitiesAndCachesMap = new HashMap<Class, Class<? extends CachedReferenceEntity>>(); while (classMappings.hasNext()) { Class aClass = ((PersistentClass) classMappings.next()).getMappedClass(); //(Class) classMappings.next(); if (ReferenceEntity.class.isAssignableFrom(aClass)) { boolean foundCache = false; for (final Class ic : aClass.getClasses()) { if (CachedReferenceEntity.class.isAssignableFrom(ic)) { if (ic.isEnum()) { referenceEntitiesAndCachesMap.put(aClass, ic); foundCache = true; } else throw new HibernateException(ic + " must be an enum since " + aClass + " is a " + ReferenceEntity.class.getName()); break; }//w ww . j a v a2 s .com } if (!foundCache) log.warn(aClass + " is marked as a ReferenceEntity but does not contain a ReferenceEntityCache enum."); // TODO: find out how to ensure the new mapping for reference type is immutable and read only // final PersistentClass pClass = getClassMapping(aClass.getLabel()); } } return referenceEntitiesAndCachesMap; }
From source file:com.medigy.persist.util.HibernateUtil.java
License:Open Source License
/** * Creates a map of all classes implementing the {@link com.medigy.persist.reference.custom.CustomReferenceEntity} * interface and the respective cached enums * * @return/* ww w . ja v a 2 s . c o m*/ */ protected static Map<Class, Class<? extends CachedCustomReferenceEntity>> getCustomReferenceEntitiesAndRespectiveEnums( final Iterator classMappings) { final Map<Class, Class<? extends CachedCustomReferenceEntity>> customReferenceEntitiesAndCachesMap = new HashMap<Class, Class<? extends CachedCustomReferenceEntity>>(); while (classMappings.hasNext()) { Class aClass = ((PersistentClass) classMappings.next()).getMappedClass(); //(Class) classMappings.next(); if (CustomReferenceEntity.class.isAssignableFrom(aClass)) { for (final Class ic : aClass.getClasses()) { if (CachedCustomReferenceEntity.class.isAssignableFrom(ic)) { if (ic.isEnum()) { customReferenceEntitiesAndCachesMap.put(aClass, ic); } else throw new HibernateException(ic + " must be an enum since " + aClass + " is a " + CachedCustomReferenceEntity.class.getName()); break; } } // if no cache is found, its ok since these are custom } } return customReferenceEntitiesAndCachesMap; }
From source file:com.medigy.service.impl.person.PersonFacadeImpl.java
License:Open Source License
/** * Creates new person (party) role and adds it to the person. * * @param person already existing Person * @param type//from w w w . j a v a 2 s.co m * @return PersonRole */ public PersonRole addPersonRole(final Person person, final PersonRoleType type) { if (!getSession().contains(person)) throw new HibernateException("Party role cannot be added to a PERSON which is not in current session."); final PersonRole respPartyRole = new PersonRole(); respPartyRole.setType(type); respPartyRole.setPerson(person); person.addRole(respPartyRole); return respPartyRole; }
From source file:com.miranteinfo.seam.hibernate.HibernateFlushEventListener.java
License:Open Source License
private boolean isEntityDirty(Object entity, String entityName) { if (!(entity instanceof BaseEntity) && !envers.isAuditedEntity(entityName)) { throw new HibernateException( "Trying to flush an object that is not an instace of BaseEntity nor an audited entity."); }//w ww.j a va2 s. co m if (entity instanceof BaseEntity) { return ((BaseEntity) entity).isDirty(); } else { return true; } }
From source file:com.moss.hibernate.URLUserType.java
License:Open Source License
public Object assemble(Serializable arg0, Object arg1) throws HibernateException { try {// w w w .j a v a 2 s . co m return new URL((String) arg0); } catch (MalformedURLException ex) { throw new HibernateException(ex); } }
From source file:com.moss.hibernate.URLUserType.java
License:Open Source License
public Object nullSafeGet(ResultSet resultSet, String[] columnNames, Object owner) throws HibernateException, SQLException { String textForm = resultSet.getString(columnNames[0]); if (textForm == null) return null; else {/*w ww. j a v a 2s .c o m*/ try { return new URL((String) textForm); } catch (MalformedURLException ex) { throw new HibernateException(ex); } } }
From source file:com.moss.jodapersist.StringTimeOfDayUserType.java
License:Open Source License
public Object nullSafeGet(ResultSet resultSet, String[] names, Object arg2) throws HibernateException, SQLException { Calendar calendar = new GregorianCalendar(timeZone); String time = resultSet.getString(names[0]); if (time == null) return null; String[] pieces = time.split(":"); if (pieces.length != 2) throw new HibernateException("Invalid format (should be hh:mm) \"" + time + "\""); return new TimeOfDay(Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1])); }
From source file:com.moss.telephone.hibernate.AreaCodeUserType.java
License:Open Source License
public Object deepCopy(Object arg0) throws HibernateException { try {/*from w ww. ja v a 2 s. c o m*/ if (arg0 == null) return null; return new AreaCode(arg0.toString()); } catch (TelephoneNumberFormatException e) { throw new HibernateException(e); } }