0

我在使用 Eclipselink JPA 时遇到了一些问题

我有两个实体:

家长

public class Journal implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@Basic(optional = false)
@NotBlank
@Size(max = 70)
@Column(name = "JOURNALNAME", unique = true, length = 70)
private String journalname;
@NotBlank
@Size(max = 70)
@Column(name = "PATHNAME", unique = true, length = 70)
private String pathname;
@Size(max = 70)
@Column(name = "ISSN", unique = true, length = 70)
private String issn;
@Size(max = 70)
@Column(name = "PRINCIPALNAME", length = 70)
private String principalname;
@Email
@Size(max = 70)
@Column(name = "PRINCIPALEMAIL", length = 70)
private String principalEmail;
@Column(name = "PRINCIPALPHONE", length = 70)
private String principalPhone;
@Size(max = 70)
@Column(name = "PRINCIPALFAX", length = 70)
private String principalFax;
@Size(max = 70)
@Column(name = "TECHNICALSUPPORT", length = 70)
private String technicalSupport;
@Email
@Size(max = 70)
@Column(name = "TECHNICALSUPPORTEMAIL", length = 70)
private String technicalSupportEmail;
@Size(max = 70)
@Column(name = "TECHNICALSUPPORTPHONE", length = 70)
private String technicalSupportPhone;
@Size(max = 200)
@Column(name = "EMAILSIGNATURE", length = 200)
private String emailSignature;
@Size(max = 4000)
@Column(name = "FOCUSSCOPE", length = 4000)
private String focusScope;
@Size(max = 4000)
@Column(name = "REVIEWPOLICY", length = 4000)
private String reviewPolicy;
@Size(max = 4000)
@Column(name = "REVIEWERGUIDELINES", length = 4000)
private String reviewerGuidelines;
@Size(max = 4000)
@Column(name = "COPYEDITORGUIDELINES", length = 4000)
private String copyeditorGuidelines;
@Size(max = 4000)
@Column(name = "PROOFREADERGUIDELINES", length = 4000)
private String proofreaderGuidelines;
@Size(max = 4000)
@Column(name = "LAYOUTEDITORGUIDELINES", length = 4000)
private String layouteditorGuidelines;
@Size(max = 4000)
@Column(name = "AUTHORGUIDELINES", length = 4000)
private String authorGuidelines;
@Column(name = "TYPICALREVIEWTIME")
private Integer typicalReviewTime;
@Size(max = 4000)
@Column(name = "DESCRIPTION", length = 4000)
private String description;
@Column(name = "HOSTED")
private boolean hosted;
@OneToMany(mappedBy = "journal", fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE})
private List<Submission> submissionList;
@OneToMany(mappedBy = "journal", cascade = {CascadeType.REMOVE})
private List<IntUserRoleJournal> intUserRoleJournalList;
@OneToMany(mappedBy = "journal")
private List<JournalSubmissionCheck> journalSubmissionCheckList;
@OneToMany(mappedBy = "journal", cascade = {CascadeType.REMOVE})
private List<Announcement> announcementList;
@OneToMany(mappedBy = "journal", cascade = {CascadeType.REMOVE})
private List<Form> formList;
@OneToMany(mappedBy = "journal", cascade = {CascadeType.REMOVE}, fetch = FetchType.LAZY)
private List<Issue> issueList;

和孩子:

public class Issue implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@Size(max = 150)
@Column(name = "IDENTIFY", length = 150)
private String identify;
@Size(max = 70)
@Column(name = "TITLE", length = 70)
private String title;
@Column(name = "VOLUME", length = 5)
private String volume;
@Column(name = "NUMBER", length = 5)
private String number;
@Column(name = "YEAR", length = 4)
private String year;
@Column(name = "PUBLISH")
private boolean publish;
@Temporal(javax.persistence.TemporalType.DATE)
Date publishDate;
@Size(max = 7000)
@Column(name = "DESCRIPTION",columnDefinition = "text")
private String description;
@Size(max = 70)
@Column(name = "COVER", length = 70, unique = true)
private String cover;
@ManyToOne
private Journal journal;
@OneToMany(mappedBy = "issue", fetch = FetchType.LAZY,
cascade = {CascadeType.MERGE, CascadeType.REMOVE})
private List<Attachment> galleyList;

问题是当我尝试创建一个新问题时。日记,作为父母总是获取我之前创建的所有问题列表。即使我设置了 fetchType.lazy。阻止其急切行为的唯一方法是删除父类中的 getter 方法。

 public String createIssue() {
    FacesMessage msg = null;
    FacesContext fc = FacesContext.getCurrentInstance();
    if (valueVolume == false
            && valueNumber == false
            && valueYear == false
            && valueTitle == false) {
        msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                "Please spesify at least one issue identification", null);
    } else {
        try {
            issue.setJournal(journal);
            setIdentify();
            JournalRegistry.getCurrentInstance().createIssue(issue);
            journal.getIssueList().add(issue);
            JournalRegistry.getCurrentInstance().updateJournal(journal);
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Issue created", null);
            reset();
        } catch (EntityAccessorException ex) {
            Logger.getLogger(HeaIssueCreateB.class.getName()).log(Level.SEVERE, null, ex);
            msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Occured error. "
                    + "Please try to refresh page or contact support", null);
        }
    }
    fc.addMessage(null, msg);
    return null;
}
4

0 回答 0