Hibernate global “dynamic-insert”

2020-07-23 04:04发布

Is there way to set the dynamic-insert attribute globally with Hibernate (so it would be the default for all entities) ?

标签: hibernate
2条回答
家丑人穷心不美
2楼-- · 2020-07-23 05:01

For Java Hibernate, the correct answer is:

Iterator mappingClasses = config.getClassMappings();
while(mappingClasses.hasNext()) {
   PersistentClass clazz = (PersistentClass) mappingClasses.next();
   clazz.setDynamicInsert(true);
   clazz.setDynamicUpdate(true);
}

Keep in mind that you have to build the mappings before you attempt to iterate over them. Otherwise config.getClassMappings() will return empty iterator.

config.buildMappings();
查看更多
Juvenile、少年°
3楼-- · 2020-07-23 05:06

in NHibernate it is

foreach (var clazz in config.ClassMappings)
{
    clazz.DynamicInsert = true;
}

i don't know the exact syntax in hibernate.

for (PersistentClass clazz : configuration.ClassMappings)
{
    clazz.setDynamicInsert(true);
}
查看更多
登录 后发表回答