If I understand you correctly, you want to receive an insert request that Hibernate runs in one database, and using code to run it in another database using entityManager#executeUpdate or similar.
Hibernate does not provide a generated query because it is specific to the dialect of the target database. So even if you received an insert request, it might be pointless.
However, in your case, you can create two database connections (via two DataSource or EntityManagerFactory regardless of your case) and call dao.persist(entity) twice for both databases, and let Hibernate handle the query construction part.
Change: By query I mean my own query here, the HQL query will be the same for both databases. Hope this helps.
source share