我有 2 个项目,员工
和数据
。这些项目代表链接到我的数据库的实体。
每个员工都有一个链接到 data
中的表的字段,因此我的 employee
pom.xml 具有数据依赖性。我的问题在于,每个数据都是由员工插入的,因此 data
也依赖于 employees
。这会导致双向依赖。
这在 Maven 中可能吗?我对maven的理解是这会导致问题。
项目员工
@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
}
数据
项目
@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 不允许循环依赖,因为它不知道首先构建哪个模块。
关于java - Maven 2 项目相互依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25853786/