本文介绍了是JPA @Embedded批注强制性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试漏报 @Embedded 标注,仍然领域已经嵌入在表中。我找不到任何事说, @Embedded 注释是可选的。

它是是不是可选?

以下code

  @Embeddable
公共类地址{
    串城市;
    串街;
}@实体
公共类Person {
    字符串名称;
    @Embedded //看来,它的作品即使这个注释丢失!?
    地址地址;
}

总是产生相同的表

 
    名称
    市
    街

就算我做的的指定 @Embedded


我的配置:


  • 的JBoss EAP 6.4.0

  • 休眠-JPA-2.0-API 1.0.1.Final-的redhat-3.jar


JPA规范说:

http://docs.oracle.com/javaee/7/api/javax/persistence/Embedded.html

http://docs.oracle.com/javaee/7/api/javax/persistence/Embeddable.html

解决方案

Embedded-Embeddable is not mandatory, but it gives you nice OOP perspective of your entities' relationship. Another way to do such a thing - is to use OneToOne mapping. But in such a case entity WILL be written to separate table (while in case of embedded it CAN be written to the separate table in your DB).

这篇关于是JPA @Embedded批注强制性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 17:57
查看更多