I'm having the following issue with a SQL Server replicated database (Database A and Database B) and JPA. In the code I have something like this:
Object obj = new Object();
obj.setName("Nico");
objFacade.create(obj);
The object is persisted in database B with ID 50000, and it's replied to database A with ID 1 (it's done by SQL Server). The problem is that when I use the same object, for example:
obj.getId() // returns 1, should be 50000
It returns object's ID from database A, which JPA is unable to find becouse it's connected to database B.
The Id in the Entity is configured like this:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
To temporarily resolve the issue, after I persist the object I run a select to bring the right object from the database.
Thanks