我正在尝试消除以下错误:
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 类:
@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 类:
@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 类:
@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 嵌入式。
最佳答案
应该是
@OneToMany(mappedBy="error", cascade=CascadeType.ALL,
targetEntity=PL704_Error_Critical.class, fetch=FetchType.EAGER)
private Collection lcritical = new ArrayList<PL704_Error_Critical>();
查看PL704_Error_Critical
中对应的属性名称:
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "PL704_ERROR_ID", referencedColumnName = "ID")
private PL704_Error error;
关于java - JPA OneToMany、ManyToOne 双向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4511051/