List of usage examples for org.hibernate.mapping Property getColumnIterator
public Iterator getColumnIterator()
From source file:org.zht.framework.service.impl.BaseServiceImpl.java
License:Apache License
private String checkUnique(M m) { // final PersistentClass clazz = factory.getConfiguration().getClassMapping(m.getClass().getName()); if (clazz == null) { throw new ServiceLogicalException("[]???"); }/*from w ww.j a va 2 s . com*/ // final Table table = clazz.getTable(); // if(table==null){ // throw new ServiceLogicalException("[]???"); // } @SuppressWarnings("unchecked") final Iterator<Property> iterator = clazz.getPropertyIterator(); if (iterator == null) { throw new ServiceLogicalException( "[]???"); } //MethodAccess access = MethodAccess.get(m.getClass()); while (iterator.hasNext()) { Property property = iterator.next(); if ("id".equals(property.getName())) { continue; } Iterator<?> columnIterator = property.getColumnIterator(); if (columnIterator.hasNext()) { Column column = (Column) columnIterator.next(); if (column.isUnique()) { Object value = (Object) access.invoke(m, "get" + ZStrUtil.toUpCaseFirst(property.getName())); //System.out.println(property.getName()+" "+value); Object id = baseDaoImpl.findIdByUnique(m.getClass(), property.getName(), value); if (id != null && !id.equals(m.getId())) { return ("?[" + value + "]?"); } } } } return null; }
From source file:org.zht.framework.zhtdao.hibernate.HibernateConfigurationUtil.java
License:Apache License
/** * ?? //from w ww.ja v a 2 s.c o m * * @param clazz * Class * @param propertyName * ?? * @return ?? */ public static <T> String getColumnName(Class<T> clazz, String propertyName) { String columnName = ""; PersistentClass persistentClass = getPersistentClass(clazz); Property property = persistentClass.getProperty(propertyName); Iterator<?> iterator = property.getColumnIterator(); if (iterator.hasNext()) { Column column = (Column) iterator.next(); columnName += column.getName(); } return columnName; }