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] Created: (OPENJPA-739) Multi thread calls to EntityManagerFactory.getEntityManager() results in org.apache.openjpa.persistence.ArgumentException
Date Tue, 07 Oct 2008 12:11:44 GMT
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


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