JPA OneToMany、ManyToOne 双向

发布于 2024-10-08 22:55:29 字数 2254 浏览 0 评论 0原文

我正在尝试消除以下错误:

实体中的属性[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2024-10-15 22:55:29

应该

@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;   

It should be

@OneToMany(mappedBy="error", cascade=CascadeType.ALL,
    targetEntity=PL704_Error_Critical.class, fetch=FetchType.EAGER)
private Collection lcritical = new ArrayList<PL704_Error_Critical>(); 

look at the corresponding property name in PL704_Error_Critical:

@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "PL704_ERROR_ID", referencedColumnName = "ID")       
private PL704_Error error;   
终陌 2024-10-15 22:55:29

映射的属性拼写不正确,可能是这个原因:

在类 PL704_Error 中,lritic 属性被颠倒为mappedBy Attribute,

@OneToMany(mappedBy="pl704_error"...

但 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

@OneToMany(mappedBy="pl704_error"...

But the variable in PL704_Error_Critical is called only error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文