So, I have project in which several WebServices will be created (REST). For the sake of simplicity, Lets name them A, B, and C. A and B handle different tasks, but both of them consume C, which is the only one with Database access.
A - Manages X Tasks
B - Manages Y Tasks
C - Manages Database Interaction
They all are packaged into WAR and deployet to Tomcat Servers. At the moment, they will coexist in the same server, but this may change down the road.
I'm facing an issue where, classess on C are annotated as per JPA standards.
Sample:
@Entity
@Table(name = "EVENT")
@NamedStoredProcedureQuery(...)
public class Event implements Serializable {
// EVENTID NUMBER
@Id
@Column(name = "EVENTID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "eventIdSequence")
@SequenceGenerator(sequenceName = "EVENTID_SEQ", initialValue = 1, allocationSize = 1, name = "eventIdSequence")
Long eventId;
// TIMESTAMP DATE
@Column(name = "TIMESTAMP")
Date timeStamp;
... some other variables ...
... getter and setters ...
}
but I use the exact same class, without annotations, on A & B.
Sample:
public class Event implements Serializable {
Long eventId;
Date timeStamp;
... some other variables ...
... getter and setters ...
}
I know I should refactor in such a way that I don't need to create each class on each project I make. So, here is my issue:
I can create a library D, which only contains these models, which A and B can simply import. However, I cannot do the same on C, because C uses annotations for database interaction.
Which should be the best approach to take, tackling this issue? Can my JPA @Entity simply extend from data class? How would column mapping go about then? Can a project without JPA dependency use JPA entity classes as simple data classes?
Any help on how to take this approach is appreciated! (if it's of any relevance, I'm currently using Spring Boot)