Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Eclipse Link error with LockType

James,

Yeah I have named queries.  Not really an option to remove them :)

Alright, I'll log the defect.

Cheers,
Eric G.

On Wed, Dec 17, 2008 at 4:01 PM, James Sutherland <jamesssss@xxxxxxxxx> wrote:
>
> This seems to be a bug in the 1.1 build with the new JPA 2.0 lockMode option.
> It defaults to NONE in the annotations, but the code is check for null.
> Please log this bug.
>
> I assume you have a Named update-all or delete-all query, this is causing
> the issue.  You could remove the named query as a workaround.
>
>
> Eric Gulatee wrote:
>>
>> Hi All,
>>
>> 1-  I'm getting the following error after upgrading to eclipselink
>> 1.1.0 M 5 while using OSGI & Spring.
>>
>> A lock type can only be used with a select query (which allows the
>> database to be locked where necessary).
>>
>> Another piece of info which may or may not be related:
>>
>> 2-  I extended org.eclipse.persistence.jpa.osgi.PersistenceProvider in
>> order to be able to externalize configuration for datasource, dialect,
>> etc... into spring.  [I have a defect open for that]  I'm not certain
>> if that may be the culprit, but I am guessing not since it's failing
>> while trying to build JPA queries.  So I have attached that.
>> Basically a rip off off the same PersistenceProvider code , aside from
>> setting the classloader.
>>
>> 3-  The M5 bundle plugin file with all dependencies should probably
>> come bundled with the 2.0 persistence preview.  [I was getting OSGI
>> failures due to javax.persistence.Cache]
>>
>> Other than that, any thoughts on the the stack trace
>>
>> org.springframework.beans.factory.BeanCreationException: Error
>> creating bean with name 'entityManager' defined in URL
>> [bundleentry://76/META-INF/spring/applicationContext-db-eclipselink.xml]:
>> Instantiation of bean failed; nested exception is
>> org.springframework.beans.factory.BeanDefinitionStoreException:
>> Factory method [public javax.persistence.EntityManager
>> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager()]
>> threw exception; nested exception is
>> javax.persistence.PersistenceException:
>> java.lang.IllegalArgumentException: A lock type can only be used with
>> a select query (which allows the database to be locked where
>> necessary).
>>       at
>> org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)
>>       at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:903)
>>       at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:817)
>>       at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
>>       at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
>>       at java.security.AccessController.doPrivileged(Native Method)
>>       at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
>>       at
>> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
>>       at
>> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
>>       at
>> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
>>       at
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
>>       at
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
>>       at
>> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
>>       at
>> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
>>       at
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:288)
>>       at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:145)
>>       at
>> com.springsource.server.kernel.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:82)
>>       at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>       at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>       at java.lang.Thread.run(Thread.java:619)
>> Caused by: org.springframework.beans.factory.BeanDefinitionStoreException:
>> Factory method [public javax.persistence.EntityManager
>> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager()]
>> threw exception; nested exception is
>> javax.persistence.PersistenceException:
>> java.lang.IllegalArgumentException: A lock type can only be used with
>> a select query (which allows the database to be locked where
>> necessary).
>>       at
>> org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:127)
>>       at
>> org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:435)
>>       ... 19 more
>> Caused by: javax.persistence.PersistenceException:
>> java.lang.IllegalArgumentException: A lock type can only be used with
>> a select query (which allows the database to be locked where
>> necessary).
>>       at
>> org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:266)
>>       at
>> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:111)
>>       at
>> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:159)
>>       at
>> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:146)
>>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>       at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>       at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>       at java.lang.reflect.Method.invoke(Method.java:597)
>>       at
>> org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
>>       ... 20 more
>> Caused by: java.lang.IllegalArgumentException: A lock type can only be
>> used with a select query (which allows the database to be locked where
>> necessary).
>>       at
>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:184)
>>       at
>> org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:94)
>>       at
>> org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:85)
>>       at
>> org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:447)
>>       at
>> org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:413)
>>       at
>> org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:1689)
>>       at
>> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:409)
>>       at
>> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
>>       at
>> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
>>       at
>> org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:213)
>>       at
>> org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:249)
>>       ... 28 more
>>
>> package da.osgi;
>>
>> import java.net.URL;
>> import java.util.Enumeration;
>> import java.util.HashMap;
>> import java.util.Map;
>>
>> import javax.persistence.EntityManagerFactory;
>> import javax.persistence.spi.ClassTransformer;
>> import javax.persistence.spi.PersistenceUnitInfo;
>>
>> import org.eclipse.persistence.exceptions.PersistenceUnitLoadingException;
>> import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl;
>> import org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider;
>> import org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl;
>> import org.eclipse.persistence.internal.jpa.deployment.JPAInitializer;
>> import
>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor;
>> import
>> org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> public class DAPersistenceProvider extends
>>               org.eclipse.persistence.jpa.osgi.PersistenceProvider {
>>
>>       static Logger logger =
>> LoggerFactory.getLogger(DAPersistenceProvider.class);
>>
>>       /**
>>        * Called by Persistence class when an EntityManagerFactory is to be
>>        * created.
>>        *
>>        * @param emName
>>        *            The name of the persistence unit
>>        * @param map
>>        *            A Map of properties for use by the persistence provider.
>> These
>>        *            properties may be used to override the values of the
>>        *            corresponding elements in the persistence.xml file or
>> specify
>>        *            values for properties not specified in the persistence.xml.
>>        * @return EntityManagerFactory for the persistence unit, or null if the
>>        *         provider is not the right provider
>>        */
>>       public EntityManagerFactory createEntityManagerFactory(String emName,
>>                       Map properties) {
>>               ClassLoader classloader = initializationHelper.getClassLoader(emName,
>>                               properties);
>>               return createEntityManagerFactory(emName, properties, classloader);
>>       }
>>
>>       /**
>>        * Called by Persistence class when an EntityManagerFactory is to be
>>        * created.
>>        *
>>        * @param emName
>>        *            The name of the persistence unit
>>        * @param map
>>        *            A Map of properties for use by the persistence provider.
>> These
>>        *            properties may be used to override the values of the
>>        *            corresponding elements in the persistence.xml file or
>> specify
>>        *            values for properties not specified in the persistence.xml.
>>        * @param classLoader
>>        *            The classloader to search for persistence units on
>>        * @return EntityManagerFactory for the persistence unit, or null if the
>>        *         provider is not the right provider
>>        */
>>       protected EntityManagerFactory createEntityManagerFactory(String emName,
>>                       Map properties, ClassLoader classLoader) {
>>               Map nonNullProperties = (properties == null) ? new HashMap()
>>                               : properties;
>>               String name = emName;
>>               if (name == null) {
>>                       name = "";
>>               }
>>
>>               JPAInitializer initializer = initializationHelper.getInitializer(
>>                               classLoader, nonNullProperties);
>>               EntityManagerSetupImpl emSetupImpl = null;
>>               // get a class loader to use with this specific EM
>>               ClassLoader currentLoader = initializationHelper.getClassLoader(emName,
>>                               nonNullProperties);
>>
>>               try {
>>                       Enumeration<URL> resources = currentLoader
>>                                       .getResources("META-INF/persistence.xml");
>>                       boolean initialized = false;
>>                       while (resources.hasMoreElements()) {
>>                               String puName = PersistenceUnitProcessor
>>                                               .buildPersistenceUnitName(PersistenceUnitProcessor
>>                                                               .computePURootURL(resources.nextElement()),
>>                                                               name);
>>
>>                               synchronized (EntityManagerFactoryProvider.emSetupImpls) {
>>                                       emSetupImpl = EntityManagerFactoryProvider
>>                                                       .getEntityManagerSetupImpl(puName);
>>                                       if (emSetupImpl == null || emSetupImpl.isUndeployed()) {
>>                                               if (!initialized) {
>>                                                       initializer.initialize(nonNullProperties,
>>                                                                       initializationHelper);
>>                                                       initialized = true;
>>                                               }
>>                                               emSetupImpl = EntityManagerFactoryProvider
>>                                                               .getEntityManagerSetupImpl(puName);
>>                                       }
>>                               }
>>
>>                               // We found a match, stop looking.
>>                               if (emSetupImpl != null) {
>>                                       break;
>>                               }
>>                       }
>>               } catch (Exception e) {
>>                       throw PersistenceUnitLoadingException
>>                                       .exceptionSearchingForPersistenceResources(currentLoader, e);
>>               }
>>
>>               // gf bug 854 Returns null if EntityManagerSetupImpl for the name
>>               // doesn't exist (e.g. a non-existant PU)
>>               if (emSetupImpl == null) {
>>                       return null;
>>               }
>>
>>               if (!initializer.isPersistenceProviderSupported(emSetupImpl
>>                               .getPersistenceUnitInfo().getPersistenceProviderClassName())) {
>>                       return null;
>>               }
>>
>>               // synchronized to prevent overriding of the class loader
>>               // and also calls to predeploy and undeploy by other threads -
>>               // the latter may alter result of shouldRedeploy method.
>>               synchronized (emSetupImpl) {
>>                       if (emSetupImpl.shouldRedeploy()) {
>>                               SEPersistenceUnitInfo persistenceInfo = (SEPersistenceUnitInfo)
>> emSetupImpl
>>                                               .getPersistenceUnitInfo();
>>                               persistenceInfo.setClassLoader(initializationHelper
>>                                               .getClassLoader(emName, properties));
>>                               if (emSetupImpl.isUndeployed()) {
>>                                       persistenceInfo.setNewTempClassLoader(initializationHelper
>>                                                       .getClassLoader(emName, properties));
>>                               }
>>                       }
>>                       // call predeploy
>>                       // this will just increment the factory count since we should
>>
>>                       // already be deployed
>>                       emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(),
>>                                       nonNullProperties);
>>               }
>>
>>               EntityManagerFactoryImpl factory = null;
>>               try {
>>                       factory = new EntityManagerFactoryImpl(emSetupImpl,
>>                                       nonNullProperties);
>>
>>                       // This code has been added to allow validation to occur without
>>                       // actually calling createEntityManager
>>                       if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
>>                               factory.getServerSession();
>>                       }
>>                       return factory;
>>               } catch (RuntimeException ex) {
>>                       if (factory != null) {
>>                               factory.close();
>>                       } else {
>>                               emSetupImpl.undeploy();
>>                       }
>>                       throw ex;
>>               }
>>       }
>>
>>       @Override
>>       public EntityManagerFactory createContainerEntityManagerFactory(
>>                       PersistenceUnitInfo info, Map properties) {
>>               ClassLoader classloader = initializationHelper.getClassLoader(info
>>                               .getPersistenceUnitName(), properties);
>>               return createContainerEntityManagerFactory(info, properties,
>>                               classloader);
>>       }
>>
>>       private EntityManagerFactory createContainerEntityManagerFactory(
>>                       PersistenceUnitInfo info, Map properties, ClassLoader classloader) {
>>               Map nonNullProperties = (properties == null) ? new HashMap()
>>                               : properties;
>>
>>               EntityManagerSetupImpl emSetupImpl = null;
>>               boolean isNew = false;
>>               ClassTransformer transformer = null;
>>               synchronized (EntityManagerFactoryProvider.emSetupImpls) {
>>                       String puName = PersistenceUnitProcessor.buildPersistenceUnitName(
>>                                       info.getPersistenceUnitRootUrl(), info
>>                                                       .getPersistenceUnitName());
>>
>>                       emSetupImpl = EntityManagerFactoryProvider
>>                                       .getEntityManagerSetupImpl(puName);
>>                       if (emSetupImpl == null) {
>>                               emSetupImpl = new EntityManagerSetupImpl();
>>                               isNew = true;
>>                               emSetupImpl.setIsInContainerMode(true);
>>                               // if predeploy fails then emSetupImpl shouldn't be added to
>>                               // FactoryProvider
>>                               transformer = emSetupImpl.predeploy(info, nonNullProperties);
>>                               EntityManagerFactoryProvider.addEntityManagerSetupImpl(puName,
>>                                               emSetupImpl);
>>                       }
>>               }
>>
>>               if (!isNew && !emSetupImpl.isDeployed()) {
>>                       transformer = emSetupImpl.predeploy(info, nonNullProperties);
>>               }
>>               if (transformer != null) {
>>                       info.addTransformer(transformer);
>>               }
>>               // When EntityManagerFactory is created, the session is only partially
>>               // created
>>               // When the factory is actually accessed, the emSetupImpl will be used
>>               // to complete the session construction
>>               EntityManagerFactoryImpl factory = new EntityManagerFactoryImpl(
>>                               emSetupImpl, nonNullProperties);
>>
>>               // This code has been added to allow validation to occur without
>>               // actually calling createEntityManager
>>               if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
>>                       factory.getServerSession();
>>               }
>>               return factory;
>>
>>       }
>>
>> }
>>
>>
>
>
> -----
> ---
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
> --
> View this message in context: http://www.nabble.com/Eclipse-Link-error-with-LockType-tp20982238p21061217.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top