aries-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Ward <>
Subject RE: entity manager aggregation?
Date Mon, 19 Jul 2010 12:56:31 GMT

Hi Jamie,

I'm a little confused as to your requirements. It sounds as though you are trying to add new
Entities (with relationships to existing entities) to an existing EntityManager at runtime.
As the JPA service specification requires the managed classes to live in the same bundle as
persistence.xml it is unlikely that you will be able to do this within the existing spec,
and I'm not sure that "merging" EntityManagers will do anything to help either.

If there are links between the existing and new Entities then these will not be accessible
via a new EntityManager unless that EntityManager also manages the instances. At this point
there is no way to consistently load the existing entities from a single client. A Foo loaded
by EntityManager1 will not be managed by EntityManager2, but would end up getting passed to
it, and there are likely to be horrendous conflicts if both EntityManagers attempt to modify
those rows in the database.

I would also like to ask why it is necessary for different bundles to contribute different
entities? If the entities are all part of the same data model then they should be part of
the same bundle. If they aren't part of the same data model then why can't they have there
own persistence unit definition?

I am not aware of any methods such as public void addEntity(class) or public void entityManagerUnion(EntityManager
mergeWithMe), but there may well be provider specific methods in OpenJPA. These would be accessible
via an unwrapped implementation and may give you the function you are looking for.

I'd be very interested to know what your use case is, as I'd like to help support people using
the Aries JPA stack where possible.



> Date: Fri, 16 Jul 2010 14:02:29 -0500
> From:
> To:
> Subject: entity manager aggregation?
> I'm trying to get a system working whereby different bundles are able to
> register different entities.
> The first thing I researched was whether there's a way to add new
> persistable entities to an entity manager at runtime. If that can be
> done then, problem solved. But I can't find a way to do that.
> The second thing I tried was to have an entity manager per registering
> bundle, and unify all the entity managers under a central persistence
> manager which would then determine which entity manager was appropriate
> for a given call. I tried this by way of having each bundle have a
> derived persistence service which proxies the usual calls (eg clear(),
> contains(Object), etc) but also has a list of class types so that it
> knows what it manages. Then, the manager calls a method
> contains(Class) to find the right manager and proxies to it. This is
> fine for stuff like clear() (clear all managers), and contains(Object)
> (find the right one), but things snag for calls like createQuery() which
> potentially involve objects across managers, such that there IS no
> appropriate manager to proxy to.
> I read through the aries JPAEntityManager in hopes it would have some
> goodies for scenarios like this, but was unable to find anything.
> The openjpa documentation explicitly says that entities CAN be added
> after startup, but I've been unable to find how one would do such a
> thing. I'm doing enhancement at build-time so, that part isn't a
> problem, I just need something like public void
> manager.addEntity(class) or public void
> manager.entityManagerUnion(EntityManager mergeWithMe).
> Am I missing something simple here?
> -Jamie

View raw message