I have 2 projects, employees
and data
. The projects represent entities linked to my db.
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.
Is this possible in maven? My understanding of maven is that this would cause problems.
project 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
project
@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.
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 does not allow circular dependencies since it would not know which module to build first.