Reputation: 71
I have an application A which has an entity Customer.
package stackoverflowTest.dao;
import javax.persistence.*;
@Entity
@Table(name = "customers")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;
@Column(name = "name")
private String name;
public Customer(String name) {
this.name = name;
}
}
Now I have an application B which will need to update the entity.
Do I have to do findOne(customer) and then do the update?
How do I manage the entity class in two applications? For example, if I change the entity(add another field) in the application A, I do not want to deploy again just to be able to update the name.
I could do it the "dirty" way; meaning I have the class in both application, and do a findOne,and then do the update.
I just wanted to know if there is a better way.
thanks.
Upvotes: 0
Views: 52
Reputation: 2230
It's easy, you can make a separate project to produce a jar file including your repository layer and entities. then by creating the jar file you can add it into both applicationA and applicationB pom.xml.
<dependency>
<groupId>com.example.app</groupId>
<artifactId>application-commons</artifactId>
<version>0.0.1</version>
</dependency>
This way you avoid repeating yourself across multiple projects .
In order to easily handle updating you jar file , you can also upload your recent versions on an Artifact Repository Manager for example: Nexus or Artifactory for easy sharing of recent jar file versions among your applications.
Upvotes: 1