java - 文档 - 如何在 hibernate hbm.xml 文件中声明 transient 方法?

标签 java hibernate hibernate-mapping hbmxml

我想在 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/

相关文章:

java - 获取部署在 weblogic 服务器上的所有应用程序的列表

java - JNA,结构和数组

java - 预期位置参数计数 : 1, 实际参数:[]

java - 用于 hibernate 实体映射的 Json 到 Java 对象的转换

java - 开始 : Applet is not initialized in Java application

java - 在 twoway-gridView 中访问 TextView

java - Spring hibernate : reload entity mappings

java - Hibernate : java. lang.ClassCastException : java. lang.Integer 无法转换为 java.lang.Double

java - 当我试图从数据库中获取数据时 hibernate "No session or session was closed"

java - hibernate中作为实体或值类型的地址