有没有一种方法(配置参数)可以更改 Hibernate 默认行为以将域类的非注释字段视为持久化?
我希望 Hibernate 默认认为非注释字段是 transient 的,并且不能考虑持久性,而不是努力使用 @Transient 注释所有这些字段。
最佳答案
根据Hibernate Reference,Hibernate 注释看起来不可能。 :
In the annotations world, every non static non transient property (field or method depending on the access type) of an entity is considered persistent, unless you annotate it as @Transient. Not having an annotation for your property is equivalent to the appropriate @Basic annotation.
当然,对于 XML 映射,您可以只添加将被映射的属性。
关于Hibernate - 忽略非注释字段而无需添加@Transient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21431995/