Maven 2项目相互依赖 [英] Maven 2 projects depend on one another

查看:551
本文介绍了Maven 2项目相互依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个项目,employeesdata.这些项目代表链接到我的数据库的实体.

I have 2 projects, employees and data. The projects represent entities linked to my db.

每个员工都有一个链接到data中的表的字段,因此我的employee pom.xml具有数据依赖性.我的问题在这里,每个数据都是由员工插入的,因此data也依赖于employees.这导致了双向依赖性.

Each employee has a field linked to a table in data and so my employee pom.xml has a dependency for data. My problem resides here, every data is inserted by an employee and so data also has a dependency on employees. This results in a bi-directional dependency.

这在行家中可能吗?我对maven的理解是,这会引起问题.

Is this possible in maven? My understanding of maven is that this would cause problems.

项目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
}

如您所见,它们彼此依赖,但是我希望它们位于不同的项目中,因为它们属于不同的架构.另外,我计划添加其他架构,这些架构我可能不想在我正在设计的系统的每个部分中公开,而只是其中的一部分.

As you can see they depend on each other but I want them in different projects as they belong to different schemas. Also I plan to add other schemas that I may not want to expose in every part of the system I am designing but only parts of it.

推荐答案

将所有与实体相关的类放在单个Maven模块中会更有意义.这样,所有类都可以相互依赖.这还将集中所有持久化的类,以将其保留在一个项目中.

It would be make much more sense to put all entity-related classes in a single Maven module. In this way, all classes can depend on each other. This will also centralize all persisted classes to be maintained in one project.

Indeed Maven不允许循环依赖,因为它不知道首先要构建哪个模块.

Indeed Maven does not allow circular dependencies since it would not know which module to build first.

这篇关于Maven 2项目相互依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆