JPA OneToMany、ManyToOne 双向
我正在尝试消除以下错误:
实体中的属性[lritic] 类[类 pl.pwc.docs.pl704.PL704_Error] 有一个 映射的 [pl704_error] 的值 不存在于其所属实体中 类[类 pl.pwc.docs.pl704.PL704_Error_Critical]。 如果所属实体类是 @MappedSuperclass,这是无效的, 并且你的属性应该引用 正确的子类。
PL704 @Entity class:
@Entity
public class PL704 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private int Status;
private String Comments;
@OneToMany(mappedBy="pl704", cascade=CascadeType.ALL, targetEntity=PL704_Error.class, fetch=FetchType.EAGER)
private Collection lerror = new ArrayList<PL704_Error>();
//getters, setters...
PL704_Error @Entity class:
@Entity
public class PL704_Error implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String ErrorType;
private String ErrorReason;
private String ErrorLocation;
private String OriginalAttributeValue;
@ManyToOne
@JoinColumn(name = "PL704_ID", referencedColumnName = "ID")
private PL704 pl704;
@OneToMany(mappedBy="pl704_error", cascade=CascadeType.ALL, targetEntity=PL704_Error_Critical.class, fetch=FetchType.EAGER)
private Collection lcritical = new ArrayList<PL704_Error_Critical>();
//getters, setters...
PL704_Error_Critical @Entity class:
@Entity
public class PL704_Error_Critical implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "PL704_ERROR_ID", referencedColumnName = "ID")
private PL704_Error error;
//getters, setters...
综上所述,一个 PL704
可以有许多PL704_Error
。一个 PL704_Error
可以有多个 PL704_Error_Critical
。
我应该如何更改代码来修复错误?
使用:EclipseLink 2.1.1,H2 嵌入式。
I'm trying to get rid of the following error:
The attribute [lcritical] in entity
class [class
pl.pwc.docs.pl704.PL704_Error] has a
mappedBy value of [pl704_error] which
does not exist in its owning entity
class [class
pl.pwc.docs.pl704.PL704_Error_Critical].
If the owning entity class is a
@MappedSuperclass, this is invalid,
and your attribute should reference
the correct subclass.
PL704 @Entity class:
@Entity
public class PL704 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private int Status;
private String Comments;
@OneToMany(mappedBy="pl704", cascade=CascadeType.ALL, targetEntity=PL704_Error.class, fetch=FetchType.EAGER)
private Collection lerror = new ArrayList<PL704_Error>();
//getters, setters...
PL704_Error @Entity class:
@Entity
public class PL704_Error implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String ErrorType;
private String ErrorReason;
private String ErrorLocation;
private String OriginalAttributeValue;
@ManyToOne
@JoinColumn(name = "PL704_ID", referencedColumnName = "ID")
private PL704 pl704;
@OneToMany(mappedBy="pl704_error", cascade=CascadeType.ALL, targetEntity=PL704_Error_Critical.class, fetch=FetchType.EAGER)
private Collection lcritical = new ArrayList<PL704_Error_Critical>();
//getters, setters...
PL704_Error_Critical @Entity class:
@Entity
public class PL704_Error_Critical implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "PL704_ERROR_ID", referencedColumnName = "ID")
private PL704_Error error;
//getters, setters...
Summing up, One PL704
can have many PL704_Error
. One PL704_Error
can have many PL704_Error_Critical
.
How should I change my code to fix an error?
Used: EclipseLink 2.1.1, H2 Embedded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该
查看
PL704_Error_Critical
中对应的属性名称:It should be
look at the corresponding property name in
PL704_Error_Critical
:映射的属性拼写不正确,可能是这个原因:
在类 PL704_Error 中,lritic 属性被颠倒为mappedBy Attribute,
但 PL704_Error_Critical 中的变量仅被调用
error
。The mapped by attribute spelling is not correct, maybe this is the cause:
In class PL704_Error the lcritical attribute is reversed mappedBy Attribute
But the variable in PL704_Error_Critical is called only
error
.