gpt4 book ai didi

hibernate - @Access 被 EclipseLink 忽略,在 Hibernate 中工作正常

转载 作者:行者123 更新时间:2023-12-01 23:48:56 24 4
gpt4 key购买 nike


我在字段上有一个带有 @EmbeddedId 的实体,并且我覆盖了字段的访问类型,使其具有 Property 访问权限。但这会被EclipseLink忽略,在Hibernate中这是可以的。由于以下原因,Netbeans 也向我显示错误:

类必须使用一致的访问类型(字段或属性)。
没有为此实体层次结构定义 ID。

@EmbeddedId
private OneId id;

@Transient
private String cosmin;

@Access(AccessType.PROPERTY) // ??
public String getCosmin() {
return cosmin;
}

public void setCosmin(String cosmin) {
this.cosmin = cosmin;
}

最佳答案

问题是实体错过了以下类级别注释:

@Access(AccessType.FIELD)

只需从 @Entity 添加下一个即可。当字段和方法都被注释时,您不知道实际使用哪种访问类型。在您的情况下,它似乎是方法访问​​,并且 @EmbeddedId 被简单地忽略。

在 JPA 2.0 规范中,这是用以下文字来说明的:

The behavior of applications that mix the placement of annotations on fields and properties within an entity hierarchy without explicitly specifying the Access annotation is undefined.
...
When Access(FIELD) is applied to such a class, it is possible to selectively designate individual attributes within the class for property access. To specify a persistent property for access by the persistence provider runtime, that property must be designated Access(PROPERTY).

.

关于hibernate - @Access 被 EclipseLink 忽略,在 Hibernate 中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10682528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com