Thanks emmanuel,
This is really helpful.
We don't have any use cases where we need to associate a collection instance with two different Hibernate sessions,
To move the entities around we are detaching it from one session then persisting it to other.
Till now we were not using generated values for ID's But replicate is working fine so when we will have use case like that we will use it.
Thanks a lot
Mayank.
emmanuel wrote:
I think your general approach works but there are a few potential gotchas:
- the same collection instance cannot be associated with two different Hibernate sessions
- to move an entity from the ORM (mysql) session to the OGM (mongodb) session, you need to be careful with the identifier. You need on the cold session a manual id generator so that you share the id between both storages and not regenerate one. Note that there is a method on Session that tries to address some of these problems, it's called replicate.
If you have collections, I would be tempted to either use replicate or something like MapStruct to do a copy from class A to class APrime. APrime could host slightly different mapping options if needed.
I would be interesting to have such hot / cold offloading pattern once we start supporting native polyglot persistence.