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 Tue, 07 Oct 2008 13:55:44 GMT

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

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

Hi,

Do you have the WebSphere Feature Pack for EJB3 or are you using a "normal" version of WebSphere
Application Server? 

The exception shown above comes from the automatic runtime enhancement feature of OpenJPA.
Have you tried enhancing the entities manually with the PCEnhancer tool or PCEnhancer ant
task? This might be another subclassing "gotcha" that needs to be documented. 

> 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