tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ulrich Stärk <...@spielviel.de>
Subject Re: PATCH: tapestry-jpa EntityManagerObjectProvider fixes entities not associated with correct entity manager issue
Date Wed, 14 Nov 2012 07:02:37 GMT
Patches sent through the mailing list are OK too, as long as the author makes it clear that
it's
intended for inclusion. Larger pieces of work need separate handling. JIRA used to have a
checkbox
that allowed the uploader to explicitly mark a patch as intended for inclusion, thus allowing
us to
keep track of this stuff. With that functionality gone it doesn't matter anymore whether a
patch is
sent over the mailing list or attached to a JIRA issue, as long as the author's intention
to have it
included is clear.

Uli

On 14.11.2012 01:52, Lenny Primak wrote:
> I am not sure why the existing code doesn't work for you as it works fine in my environment.

> Another thing is that patches belong in JIRA and cannot be taken from mailing lists due
to copyright issues. 
> 
> Perhaps Igor can shed some light on this?
> 
> On Nov 13, 2012, at 7:48 PM, "John" <john@quivinco.com> wrote:
> 
>> I put this on the users group recently to complete a thread, it belongs here really
I suppose.
>>
>> The problem manifests when multiple PUs are defined in persistence.xml and then referred
to in classes using the @PersistenceContext(unitName= annotation. As it is in 5.3.6 the first
EntityManager wired up gets injected to all successive EntityManager instances and the unitName=
value is ignored. Probem was caused by reusing a class variable. The bug makes it seem that
entities are not wired to the EntityManager as you would expect, in fact the reference passed
in is bad.
>>
>> Also refactored to use PlasticProxyFactory.
>>
>> John
>>
>>
>> ----- Original Message ----- From: John
>> To: Tapestry users
>> Sent: Tuesday, November 13, 2012 7:51 AM
>> Subject: PATCH: tapestry-jpa EntityManagerObjectProvider fixes entities not associated
with correct entity manager issue
>>
>>
>> This looks like a bug where a class member variable is used to cache the EntityManager
that is subsequently handed to all the PersistenceContext annotations regardless of the unitName,
like I said.
>>
>> The following replacement class is tested working and handles multiple persistence
units correctly as per the original Tapestry docs, just put it on your classpath first. Maybe
someone on the developer side can check this out and commit it to the build cycle.
>>
>>
>> package org.apache.tapestry5.internal.jpa;
>>
>> import javax.persistence.EntityManager;
>> import javax.persistence.PersistenceContext;
>>
>> import org.apache.tapestry5.ioc.AnnotationProvider;
>> import org.apache.tapestry5.ioc.ObjectCreator;
>> import org.apache.tapestry5.ioc.ObjectLocator;
>> import org.apache.tapestry5.ioc.ObjectProvider;
>> import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
>> import org.apache.tapestry5.jpa.EntityManagerManager;
>>
>> /**
>> * A patched version to use PlasticProxyFactory and not cache the EntityManager as
a class member.
>> * @author John Coleman
>> */
>> public class EntityManagerObjectProvider implements ObjectProvider
>> {
>>
>>   /**
>>    * {@inheritDoc}
>>    */
>>   public <T> T provide(final Class<T> objectType, final AnnotationProvider
annotationProvider,
>>           final ObjectLocator locator)
>>   {
>>       if (objectType.equals(EntityManager.class))
>>           return objectType.cast(getOrCreateProxy(annotationProvider, locator));
>>
>>       return null;
>>   }
>>
>>   private synchronized EntityManager getOrCreateProxy(
>>           final AnnotationProvider annotationProvider, final ObjectLocator objectLocator)
>>   {
>>           final PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory",
>>             PlasticProxyFactory.class);
>>
>>            final PersistenceContext annotation = annotationProvider
>>                           .getAnnotation(PersistenceContext.class);
>>
>>           EntityManager proxy = proxyFactory.createProxy(EntityManager.class, new
ObjectCreator<EntityManager>()
>>           {
>>               public EntityManager createObject()
>>               {
>>                   final EntityManagerManager entityManagerManager = objectLocator
>>                           .getService(EntityManagerManager.class);
>>
>>                   return JpaInternalUtils.getEntityManager(entityManagerManager,
annotation);
>>               }
>>           }, "<EntityManagerProxy>");
>>
>>       return proxy;
>>   }
>>
>> } 
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Mime
View raw message