我想在 hibernate 实体中声明一个 transient 方法,并且我们使用 hbm.xml 文件进行映射而不是注释。
我在网上看到很少有人在 xml 中声明 transient 字段,用注释声明 transient 方法,但我找不到在 xml 中声明 transient 方法的文档。我看到一些提到如果它不在 hbm.xml 文件中 Hibernate 将忽略它,但我想确认一下。
这方面的文档在哪里?
最佳答案
从 Hibernate 5 开始,遗留的 XML 映射文档似乎已被删除。但是您仍然可以在 Hibernate 4 documentation, section 5 中找到它的文档。 .
使用hbm.xml
时也是如此,如果您不需要映射字段或方法,只需不要将其包含在hbm.xml
中即可。我找不到文档中明确提及此行为,因为我认为人们会回想起只有旧版 XML 映射的时代,这是一种常识。
并且在引入注解映射之后,引入了默认自动检测映射字段的功能,不需要显式声明所有映射字段。遗留 XML 和注释映射之间的这种行为差异在文档中以某种方式隐式提及,如下所示:
You need to decide which property needs to be made persistent in a given entity. This differs slightly between the annotation driven metadata and the hbm.xml files.
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.
关于java - 文档 - 如何在 hibernate hbm.xml 文件中声明 transient 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57469721/