0

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.

L. Young
  • 163
  • 3
  • 7
  • 24

1 Answers1

1

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.

M A
  • 71,713
  • 13
  • 134
  • 174
  • I want to separate them for 2 reasons 1) They have different schemas 2) I will eventually add more schemas and I want to provide parts of them to certain parts of the code. I don't want everything to be available everywhere. For this reason I am using different projects. – L. Young Sep 15 '14 at 17:56
  • I don't know much about your data model, but even if they have different database schemas, it would still be more logical to put them in one module. Concerning the second reason, I think there is a way in Maven to generate a "subpackage" of your module. So if a project depends on only a subset of the entities, you could still be able to do that even if you have them all in one module. You could read about profiles and [how to exclude content from a jar artifact](http://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html). – M A Sep 15 '14 at 18:28
  • 1
    I think you're right, it would be better to have them in the same project under 1 persistence unit. If they depend on eachother when exposing one I need to expose the other anyway or I can get errors. Thank you! – L. Young Sep 15 '14 at 18:41
  • * different persistence units within the same xml sorry as I am still keeping them in different schemas – L. Young Sep 15 '14 at 19:13