public final class EntityUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
evictEmptyProperty(Object entity)
清除实体类中引用的无效(外键)属性.
|
static <T extends Entity<?>> |
extractIds(Collection<T> entities)
extractIds.
|
static <T extends Entity<?>> |
extractIdSeq(Collection<T> entities)
extractIdSeq.
|
static String |
getCommandName(Class<?> clazz)
getCommandName.
|
static String |
getCommandName(Object obj)
getCommandName.
|
static String |
getCommandName(String entityName)
getCommandName.
|
static String |
getEntityClassName(Class<?> clazz)
为了取出CGLIB代来的代理命名
|
static boolean |
isEmpty(Entity<?> entity,
boolean ignoreDefault)
判断实体类中的属性是否全部为空
|
static boolean |
isExpired(TemporalAt entity)
isExpired.
|
static boolean |
isExpired(TemporalOn entity) |
static void |
merge(Object dest,
Object orig)
Deprecated.
|
static void |
populate(Map params,
Entity entity) |
public static <T extends Entity<?>> List<?> extractIds(Collection<T> entities)
extractIds.
T - a T object.entities - a Collection object.List object.public static <T extends Entity<?>> String extractIdSeq(Collection<T> entities)
extractIdSeq.
T - a T object.entities - a Collection object.String object.public static boolean isEmpty(Entity<?> entity, boolean ignoreDefault)
entity - a Entity object.ignoreDefault - 忽略数字和字符串的默认值public static boolean isExpired(TemporalAt entity)
isExpired.
entity - a TemporalAt object.public static boolean isExpired(TemporalOn entity)
public static void evictEmptyProperty(Object entity)
hibernate在保存对象是检查对象是否引用了未持久化的对象,如果引用则保存出错.
实体类(Entity)是否已经持久化通过检查其id是否为有效值来判断的.
对于实体类中包含的
<code>
Component
</code>
则递归处理
因为集合为空仍有其含义,这里对集合不做随意处理.如
// evict collection
if (value instanceof Collection) {
if (((Collection) value).isEmpty())
map.put(attr, null);
}
entity - ValidEntityPredicatepublic static void merge(Object dest, Object orig)
merge函数主要用来将页面回传对象(orig)的参数合并到数据库已经存在的对象中.(浅拷贝)
合并的依据是待合并对象是否为空.如果对象是平面的component 则递归处理,如果是entity则检查是否是
有效的持久化对象(id不为空或者0),那么将该对象复制过去,否则复制null.
这些页面对象中的集合属性不包括在复制和合并范围内.因为大多数页面参数中,很少有集合(Set)参数
况且如果把空集合合并到已有对象上,反而会造成(hibernate)删除已有对象和这些对象的关联,甚至对象本身
将orig中不为空的属性复制到dest中 added at
两个对象必须是同一类型的
dest - orig - 影响destEntityUtil#evictEmptyPropertyCopyright © 2005–2018 The Beangle Software. All rights reserved.