And*_*ing 5 java inheritance hibernate jpa
我尝试了很多不同的东西,做了大量的研究,但仍然无法完成以下工作:我想@NamedEntityGraph
在一个实体上定义一个,但我引用的属性位于父类中,该类定义为@MappedSuperclass
.
我有轻微的感觉(在检查代码如何构建实体图之后),这不起作用,但也许有人可以对它有所了解.
这里详细介绍了我们要做的事情(缩短了一些事情):
@MappedSuperclass
public class UserBase {
private Long id;
private String loginname;
private String password;
@ManyToMany(fetch = FetchType.LAZY)
private Set<Role> roles;
....
}
Run Code Online (Sandbox Code Playgroud)
而实际的实体:
@Entity
@NamedEntityGraph(
name = "withRoles",
attributeNodes = { @NamedAttributeNode("roles") })
public class User extends UserBase {
....
}
Run Code Online (Sandbox Code Playgroud)
会发生什么,我们得到错误
Unable to locate Attribute with the the given name [roles] on this ManagedType [some.package.path.User]
Run Code Online (Sandbox Code Playgroud)
单步执行图创建代码,我可以看到它只查看类本身定义的属性,而不是超类型.我有可能以这种方式定义图形,这有效吗?
谢谢你的任何提示!
尝试添加includeAllAttributes=true
:
@NamedEntityGraph(
name = "withRoles",
includeAllAttributes=true
attributeNodes = { @NamedAttributeNode("roles") })
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1215 次 |
最近记录: |