openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dick (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-739) Multi thread calls to EntityManagerFactory.getEntityManager() results in org.apache.openjpa.persistence.ArgumentException
Date Wed, 08 Oct 2008 14:19:44 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-739?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12637937#action_12637937
] 

Michael Dick commented on OPENJPA-739:
--------------------------------------

EntityManagerFactories are (or need to be) thread safe (EMs are not). It would be interesting
to see if the problem only occurs when you use the subclassing support though. Sadly the subclassing
support yields very different behavior from the "normal" enhancement path. So when we see
it in the stack we tend to run the PCEnhancer first to eliminate it as a possibility.

The questions about the feature pack were just to make sure there were no conflicts with the
version of OpenJPA that ships with the feature pack. 

I suspect that using build time enhancement will resolve the problem, but may not be permanent
solution. The subclassing support is re-reading the metadata for your entities - it's this
scan of the meta data that apparently isn't thread safe. Can you try using the PCEnhancer
and seeing if that does resolve the issue? 

> Multi thread calls to EntityManagerFactory.getEntityManager() results in org.apache.openjpa.persistence.ArgumentException
> -------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-739
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-739
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.1.0
>         Environment: OS->Windows XP SP2  
> App Server-> IBM Websphere App Server v6.1.0.13 
> JDK-> IBM JDK v1.5 
> JPA-> release 1.1.0
>            Reporter: Sachin Deshpande
>            Priority: Critical
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Multi thread calls to EntityManagerFactory.getEntityManager() results in 
> <openjpa-1.1.0-r422266:657916 fatal user error> org.apache.openjpa.persistence.ArgumentException:
Field "*.*.*.entity.Rtlr.consCollection" declares "*.*.*.entity.Cons.rtlrCd" as its mapped-by
field, but this field is not a direct relation.
> 	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:126)
> 	at org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy.map(RelationCollectionInverseKeyFieldStrategy.java:95)
> 	at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:120)
> 	at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:80)
> 	at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:438)
> 	at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:403)
> 	at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:812)
> 	at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1625)
> 	at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:717)
> 	at org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:677)
> 	at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:555)
> 	at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
> 	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:248)
> 	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:219)
> 	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
> 	at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:121)
> 	at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:310)
> 	at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:228)
> 	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:190)
> 	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
> 	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
> 	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
> 	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
> 	at *.*.*.utility.DBUtilities.getEntityManager(DBUtilities.java:20)
>        ...
>        ...
>        ...
>       To access all EntityManagers we have the following custom class:
> public class DBUtilities {
> 	private static EntityManagerFactory emf = null;
> 	
> 	static {
> 		CommonResources resource = CommonResources.getInstance();
> 		String env = resource.getValue("jndi.persistanceUnit.use");
> 		emf = Persistence.createEntityManagerFactory(env);
> 	}
> 	
> 	/**
> 	 * Return Entity Manager
> 	 * @return
> 	 */
> 	public static EntityManager getEntityManager() {
> 		return emf.createEntityManager();
> 	}
> }
>        The code is supposed to run in a multi-threaded environment where parallel threads
invoke DBUtilities.getEntityManager() method. In such a scenario, we get the above exception.
>       However, if we 'synchronize' the DBUtilities's getEntityManager() method, the exception
does not occur and the code executes successfully. 
>       This is contrary to our understanding that EntityManagerFactory is thread safe
and EntityManagerFactory's .createEntityManager() method creates a new instance of EntityManager
everytime though being invoked by multiple threads.
>       Please advice.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message