我可以同时拥有 JDO 和 JPA 注释吗?
如果我为数据对象上的 JPA 和 JDO 提供全套注释,实际上会发生什么?
我可以在不接触代码的情况下在它们之间切换吗?如何切换播放外部配置文件的内容?我知道 META-INF 中有 persistence.xml jdoconfig.xml 但我不明白如何使用它们。 (可能是压缩解释的链接?) 目前,我已将两个文件就位,并且下面的代码编译正常。我对幕后的内容感兴趣,以了解这种方法的含义。
举个生动的例子:
@Entity
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
class B
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Persistent
@Basic
private String name;
}
平台:Google AppEngine 1.4的默认设置它使用DataNucleus增强器(版本1.1.4)
What will actually happen if I provide a full set of annotations for JPA and JDO on data objects?
Can I then switch between them without touching the code? how can I switch what to aplay external configuration files? I know in the META-INF there are persistence.xml jdoconfig.xml but I do not understand the how to use them. (may be a link to a compressive explanation?)
Currently I got both files in place and the code below compiles Ok. I am interested in what goes under the hood to understand implications of this approach.
For vivid example:
@Entity
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
class B
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Persistent
@Basic
private String name;
}
Platform: default setup of Google AppEngine 1.4 it uses DataNucleus Enhancer (version 1.1.4)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我从未尝试过这个,但它应该有效。这就是注释的要点:除非使用它们,否则不会影响代码。 JPA 实现使用其注释,JDO 使用其他注释。
Although I have never try this it should work. This is the point of annotations: the do not affect the code unless they are used. JPA implementation uses its annotations, JDO uses others.