[英]Maven 2 projects depend on one another
我有2個項目, employees
和data
。 這些項目代表鏈接到我的數據庫的實體。
每個員工都有一個鏈接到data
表的字段,因此我的employee
pom.xml具有數據依賴性。 我的問題就在這里,每個數據都是由雇員插入的,因此data
也依賴於employees
。 這導致雙向依賴性。
這可能在行家中嗎? 我對Maven的理解是,這會引起問題。
項目employees
@Entity
@Table(name="employees", uniqueConstraints= {
@UniqueConstraint(columnNames="idEmployees"),
@UniqueConstraint(columnNames="idCardNumber"),
@UniqueConstraint(columnNames="niNumber")
})
public class Employee {
@Id
@GeneratedValue
@Column(unique=true, nullable=false, updatable=false)
private int idEmployees;
//other class variables
@ManyToOne(cascade=CascadeType.PERSIST, fetch=FetchType.LAZY)
@JoinColumn(name="niCategoryId", nullable=false, updatable=false)
private NIData niCategory;
//constructors getter and setters
}
data
項目
@Entity
@Table(name="nidata", uniqueConstraints= {
@UniqueConstraint(columnNames="idNiData")
})
public class NIData {
@Id
@GeneratedValue
@Column(unique=true, nullable=false, updatable=false)
private int idNiData;
//other class variables
@ManyToOne(cascade=CascadeType.PERSIST, fetch=FetchType.LAZY)
@JoinColumn(name="createdEmployeeId", nullable=false, updatable=false)
private Employee createdEmployee;
//constructors getter and setters
}
如您所見,它們彼此依賴,但是我希望它們位於不同的項目中,因為它們屬於不同的架構。 另外,我計划添加其他架構,這些架構我可能不想在正在設計的系統的每個部分中公開,而只希望公開其中的一部分。
將所有與實體相關的類放在單個Maven模塊中會更有意義。 這樣,所有類都可以相互依賴。 這還將集中所有持久化類,以將其保留在一個項目中。
實際上,Maven不允許循環依賴,因為它不知道首先要構建哪個模塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.