openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sachin Deshpande (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 05:55:44 GMT

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

Sachin Deshpande commented on OPENJPA-739:
------------------------------------------

Hi Michael,

We are using IBM Websphere App Server v6.1.0.13  with WebSphere Feature Pack for Webservices
(v6.1.0.13). We have not installed WebSphere Feature Pack for EJB3.  We have not used PCEnhancer
tool or PCEnhancer ant task.

We have generated the entity classes from RAD (Rational Application Developer) v 7.5. We have
used these entity classes in our current DEV environment which uses Rational Software Architect
(RSA ) v. 7.0.0.6. The JPA compile time and build time support is provided by  "web-jpa-dev.jar"

that comes with Rational Application Developer v 7.5.

But we wonder how 'synchronizing' the DBUtilities's getEntityManager() method resolved the
issue. Is EntityManagerFactory's .createEntityManager() thread safe?

Thanks,


> 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