Search code examples
jpaeclipselink

insert data to another database in jpa having multiple persistence unit


I have two databases in the same web application. user1 located in database1 receives a notification from another user2 located in database2. So, I have to insert in the table notification of database1 a row containing the object of notification and the sender(user2). My question is can I insert a user object in another database ?


Solution

  • Yes, you can have the same entity mapped in two persistence units - each persistence unit representing a different database. So the user entity can be persisted to two database if that is what you are going for. You will need to create and name two separate persistence units and specify the unitName when using injection to differentiate between the two.