Andrig Miller [
http://community.jboss.org/people/andy.miller%40jboss.com] replied to the
discussion
"Multiple Persistence Units with the same entities"
To view the discussion, visit:
http://community.jboss.org/message/536638#536638
--------------------------------------------------------------
jaikiran pai wrote:
> Andrig Miller wrote:
>
>
> So, I created two persistence units in my persistence.xml, with two different sets
of Hibernate properties, pointing at the same database, and let it default to scanning for
the Entities in my jar.
>
I missed this earlier. So effectively, you are sharing the same entities between multiple
entity managers. Do those entity managers really "share" those entities in your
application? For example, if you try to access an entity which is shared (i.e. you access
the entity using both the entity managers) then you will end up running into issues
because each of these entity managers, that come from different entity manager factories,
will (possibly) hold a different state.
Well, I don't use the same entities from
two different entity manager's at the same time, or within the same transaction. One
entity manager is used to do an initial data load of a bunch of reference data into the
database, and the other entity manager is used for transaction processing against that
data. The two processes are independent, and the OLTP processing cannot occur until after
the batch process has completed anyway. So, there is no overlap, where the same entity
would be used in two entity managers at the same time, and have different state.
Before even doing this, I thought through that, but is this something that is compliant
with the spec. All the reading I have done, only vaguely hint at having the same entities
into two different persistence units, and everything I have read basically says that a
persistence unit is tied to one data source (maybe implying that multiple persistence
units should have "unique" data sources).
So, while it works now, and based on the functions involved, there is no overlap, will
this continue to work in the future? If its not supported by the spec, then I have a
reasonable expectation that this might break in the future.
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/536638#536638]
Start a new discussion in EJB 3.0 at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]