简体   繁体   English

JPA中的Xml类型映射(EclipseLink / Oracle Toplink)

[英]Xml Type Mapping in JPA (EclipseLink/Oracle Toplink)

According to James and Tomas Mapping Oracle XMLType on JPA (EclipseLink) , XMLType fields are handled(mapping and persist) using @Customizer and DescriptorCustomizer. 根据James和Tomas 在JPA(EclipseLink)上映射Oracle XMLType,使用@Customizer和DescriptorCustomizer处理XMLType字段(映射并持久化)。

I have few doubts on this approach. 我对此方法毫不怀疑。

  1. Why the xmlField attribute don't need @Column anotation? 为什么xmlField属性不需要@Column注释?
  2. Why we go for DescriptorCustomizer for maapping the xmlField? 为什么我们选择DescriptorCustomizer来映射xmlField? This is only for mapping the fields? 这仅用于映射字段吗? Or it can also persist that field? 还是它可以坚持那个领域?
  3. DirectToXMLTypeMapping can be used for Object type? DirectToXMLTypeMapping可以用于对象类型吗? (Please refer: http://docs.oracle.com/cd/E15051_01/web.1111/b32441/relmapun.htm#CHDFIFEF ) (请参阅: http : //docs.oracle.com/cd/E15051_01/web.1111/b32441/relmapun.htm#CHDFIFEF
  4. As of Tomas post how that xmlField will be persist? 截至Tomas发布,该xmlField将如何持久保存? Need to write Callback methods? 需要编写回调方法吗?

Please clarify me.Sorry if my question is pointless. 请澄清一下。抱歉,我的问题没有意义。 Please provide some links and documentation to understand the XMLType fields mapping in JPA(EclipseLink/Oracle Toplink). 请提供一些链接和文档,以了解JPA(EclipseLink / Oracle Toplink)中的XMLType字段映射。

XMLType is a specialized Oracle field type, and I'm guessing does not work well with a simple basic JPA mapping. XMLType是一种特殊的Oracle字段类型,我猜想在简单的基本JPA映射中效果不佳。 EclipseLink has a custom DirectToXMLTypeMapping type that can handle conversions of the Oracle XMLType to/from a java String. EclipseLink具有自定义的DirectToXMLTypeMapping类型,该类型可以处理Oracle XMLType到Java String的转换。 In the example you've posted, the customizer is first removing the existing mapping that gets created through annotations for the "xmlField" attribute. 在您发布的示例中,定制程序首先删除通过“ xmlField”属性的注释创建的现有映射。 This essentially wipes out any @Column information that might have been added. 这实际上清除了所有可能已添加的@Column信息。 It then adds a new DirectToXMLTypeMapping containing all information required for the field, so there is no need to use annotations on the attribute. 然后,它将添加一个新的DirectToXMLTypeMapping,其中包含该字段所需的所有信息,因此无需在属性上使用批注。

Alternatively, you could define the @Column annotation and any other settings, and instead of just removing the mapping, you could get the DatabaseMapping object from the descriptor and pull the column name and other values from it to populate the new DirectToXMLTypeMapping. 另外,您可以定义@Column批注和任何其他设置,而不仅仅是删除映射,还可以从描述符中获取DatabaseMapping对象,并从描述符中提取列名称和其他值以填充新的DirectToXMLTypeMapping。

A mapping is something that describes how the attribute in your entity relates to a database field. 映射描述了实体中的属性与数据库字段之间的关系。 So it should handle retrieval as well as inserts/updates, converting it to/from the java type into/from the database type. 因此,它应该处理检索以及插入/更新,将其与java类型转换为数据库类型。 In the link you posted, the entity's xmlType attribute mapping converts the Java String into an Oracle XMLType on persist, and reverses it when reading back from the DB. 在您发布的链接中,实体的xmlType属性映射在持久化时将Java String转换为Oracle XMLType,并在从数据库读回时将其反转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM