使用 JAXB 将 xml 映射到 jpa 实体
是否可以使用 JAXB 将 xml 映射到 jpa 实体? Eclipselink Moxy 有帮助吗?
Isn't it possible to map xml to jpa entities using JAXB? Will Eclipselink Moxy be helpful?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:我是EclipseLink JAXB (MOXy) 的领导者和 JAXB 2 的成员(JSR-222)专家组。
是的,您可以将 JPA 实体映射到 XML,下面是 EclipseLink JAXB (MOXy) 使这变得更容易的一些方法。
1.双向映射
客户
地址
了解更多信息< /em>
2.映射复合键关系
我们通常会考虑将对象树映射到 XML,但是 JAXB 支持使用
@XmlID
/@XmlIDREF
用于映射表示图形的节点之间的关系。标准机制是一键对应一个外键。 JPA 支持复合键的概念,MOXy 使用@XmlKey
和@XmlJoinNodes
也支持复合键的概念(类似于 JPA 中的@XmlJoinColumns
)。员工
电话号码
了解更多信息
3. MOXy 允许复合和嵌入式密钥
JPA 还可以使用嵌入式密钥类来表示复合密钥。 MOXy 也支持这种类型的复合键。
了解更多信息
4. EclipseLink JAXB (MOXy) 和 EclipseLink JPA 具有共享概念
EclipseLink 提供共享公共核心的 JAXB 和 JPA 实现。这意味着它们共享许多相同的概念,例如:
虚拟访问方法
EclipseLink 支持虚拟属性的概念。当您创建需要按租户进行自定义的多租户应用程序时,这非常有用。 EclipseLink 的 JPA 和 JAXB 实现都支持这个概念。
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.
Yes you can map JPA entities to XML, and the following are some ways that EclipseLink JAXB (MOXy) makes this easier.
1. Bidirectional Mappings
Customer
Address
For More Information
2. Mapping Compound Key Relationships
We normally think of mapping a tree of objects to XML, however JAXB supports using the combination of
@XmlID
/@XmlIDREF
to map relationship between nodes representing a graph. The standard mechanism is one key, to one foreign key. JPA supports the concept of composite keys and so does MOXy using@XmlKey
and@XmlJoinNodes
(similar to@XmlJoinColumns
in JPA).Employee
PhoneNumber
For More Information
3. MOXy allows for Composite and Embedded Keys
JPA can also use embedded key classes to represent composite keys. MOXy also supports this style of composite keys.
For More Information
4. EclipseLink JAXB (MOXy) and EclipseLink JPA Have Shared Concepts
EclipseLink provides both JAXB and JPA implementations that share a common core. This means that they share many of the same concepts, such as:
Virtual Access Methods
EclipseLink supports the concept of virtual properties. This is useful when creating a multi-tenant application where you want per-tenant customizations. This concept is upported in both EclipseLink's JPA and JAXB implementations.