testeurFou
testeurFou

Reputation: 71

JPA: 2 applications needing to update one object

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.

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

Answers (1)

Mohammadreza  Alagheband
Mohammadreza Alagheband

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

Related Questions