List of usage examples for org.hibernate.mapping Column isNullable
public boolean isNullable()
From source file:org.zht.framework.service.impl.BaseServiceImpl.java
License:Apache License
private String checkNotNull(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. c o m //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.isNullable()) { Object value = (Object) access.invoke(m, "get" + ZStrUtil.toUpCaseFirst(property.getName())); //System.out.println(property.getName()+" "+value); if (ZStrUtil.trimToNullIfStr(value) == null) { return (" [" + property.getName() + "] ?"); } } } } return null; }
From source file:org.zht.framework.service.impl.BaseServiceImpl.java
License:Apache License
@SuppressWarnings("unchecked") private String checkmanyTone$OneToOneNullForeign(M m) { // final PersistentClass clazz = factory.getConfiguration().getClassMapping(m.getClass().getName()); if (clazz == null) { throw new ServiceLogicalException("[]???"); }/*from w w w . j a v a 2s. c o m*/ 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; } Field field = null; try { field = m.getClass().getDeclaredField(property.getName()); if (!(field.isAnnotationPresent(javax.persistence.ManyToOne.class) || field.isAnnotationPresent(javax.persistence.OneToOne.class))) { continue; } } catch (Exception e) { continue; } Iterator<?> columnIterator = property.getColumnIterator(); if (columnIterator.hasNext()) { Column column = (Column) columnIterator.next(); Object value = (Object) access.invoke(m, "get" + ZStrUtil.toUpCaseFirst(property.getName())); if (!column.isNullable()) { if (ZStrUtil.trimToNullIfStr(value) == null) { return (" [" + property.getName() + "] ?"); } MethodAccess accessZZZ = MethodAccess.get(value.getClass()); Object foreignModelId = (Object) accessZZZ.invoke(value, "getId"); if (foreignModelId == null) { return (" [" + property.getName() + "] ?"); } } else { if (ZStrUtil.trimToNullIfStr(value) != null) { Object foreignModelId = null; foreignModelId = ZPropertyUtil.getInvokeValue(value, "getId"); if (foreignModelId != null && foreignModelId.equals(-972855736L)) { throw new ServiceLogicalException("[]??"); } if (foreignModelId == null) { value = null; access.invoke(m, "set" + ZStrUtil.toUpCaseFirst(property.getName()), value); } // } // else{ // valueTemp=null; // access.invoke(m, "set"+ZStrUtil.toUpCaseFirst(property.getName()),valueTemp); // } } } } return null; }