s.grinovero wrote:
What about having just one persistence unit managing all this complexity transparently for you application?
Did you read about Hibernate Shards?
http://www.hibernate.org/hib_docs/shards/reference/en/html/preface.htmlBesides this, I wouldn't recommend having foreign keys between databases.
Thanks for this tip on Shards; but because I don't know Shards I didn't want to start another costly experience on this in my project -:)
I finally found out what I have to do to use different schemas for my entities:
(see also
http://forum.hibernate.org/viewtopic.php?p=2377634#2377634)
- create a different persistent unit for each schema in
persistence.xml (meaning: you have to use different EntityManagers in your app!)
- force Hibernate to not use
autodetection on annotated classes whilest validating the mappings, but to use the
<class> elements from
persistence.xml
- create different "orm" files for each persistent units if you have externalized queries and declare them in the
<mapping-file> element of
persistence.xml
- annotate the EnityManager instances you are using in your app with
@PersistenceContext(unitName="xxxxxx"
Finally, I changed my foreign key relationship from one schema to the other by using something like a "weak" reference: I do not map the related entity but use just an integer attribute to hold the primary key of the entity from the other schema. This of course means: you have to do the housekeeping yourself and you cannot rely on the automatics you normally can use with an ORM.
Carlo[/url]