Error on first query [message #897627] |
Tue, 24 July 2012 19:58 |
Peter Zeltins Messages: 8 Registered: July 2012 |
Junior Member |
|
|
EL 2.4, Spring 3.1, Mysql 5, Tomcat 6, EL is set up for static weaving.
I have Spring creating my EMF and injecting all properties information into PU. I use TomcatInstrumentationClassLoader in my webapp.
The first few queries that are executed right after starting up my application context invariably fail with
[0, 101] The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM.
The query in question is:
select distinct t from com.mydomain.myentity t where t.recstatus=0 and t.fileline=0
However, I have seen this happen on simple 'select t from myentity t' query as well.
The same query executes fine next time.
I can reproduce this error in unit tests ONLY if I run them, not debug. If I step through the test same query executes fine.
It almost seems to me this has got something to do with persistence environment initialization - like its not fully set up when I run my initial queries.
Here is my Spring ORM context config:
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" mode="proxy"/>
<bean id="dataConfigPropertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="location" value="WEB-INF/config/${build_environment}.properties" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver" p:url="${hibernate.db_uri}" p:username="${hibernate.db_user}" p:password="${hibernate.db_password}"
/>
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="dataSource"></property>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceUnitManager-ref="persistenceUnitManager"
p:persistenceUnitName="MyPersistenceUnit" p:jpaVendorAdapter-ref="jpaAdapter" >
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" p:showSql="true"/>
and here is persistence.xml:
<persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<class>com.mydomain.myentity</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.weaving" value="static"/>
</properties>
</persistence-unit>
</persistence>
Any hints on how to fix this would be appreciated!
Peter
|
|
|
|
Re: Error on first query [message #897980 is a reply to message #897946] |
Wed, 25 July 2012 14:40 |
Peter Zeltins Messages: 8 Registered: July 2012 |
Junior Member |
|
|
Here is full stack trace:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [select distinct t from com.mydomain.models.myEntity t where t.recstatus=0 and t.fileline=0].
[0, 101] The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1512)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1532)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy26.createQuery(Unknown Source)
at com.mydomain.TransactionsDAO.getTransactions(TransactionsDAO.java:169)
at com.mydomain.TransactionsDAO$$FastClassByCGLIB$$32cab5b7.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.mydomain.TransactionsDAO$$EnhancerByCGLIB$$32bc7e1c.getTransactions(<generated>)
at com.mydomain.TransactionStatusChecker.checkTransactionsStatus(TransactionStatusChecker.java:30)
at com.mydomain.TransactionStatusChecker$$FastClassByCGLIB$$5dbbb251.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.mydomain.TransactionStatusChecker$$EnhancerByCGLIB$$bf48da1a.checkTransactionsStatus(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:165)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [select distinct t from com.mydomain.models.myEntity t where t.recstatus=0 and t.fileline=0].
[0, 101] The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:150)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:325)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:270)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:157)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:138)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:112)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:98)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:82)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1510)
... 39 more
And this is excerpt from code:
@PersistenceContext(type=PersistenceContextType.TRANSACTION,unitName="myPersistenceUnit")
protected EntityManager em;
TypedQuery<MyEntity> _query = em.createQuery(_sql, MyEntity.class);
if ( filterArgs != null && filterArgs.length > 0 ) {
for ( int i=0; i<filterArgs.length; i++) {
_query.setParameter(i+1, filterArgs[i]);
}
}
Collection<MyEntity> _retval = _query.getResultList();
Thanks for looking into this!
Peter
|
|
|
|
Re: Error on first query [message #898646 is a reply to message #898015] |
Fri, 27 July 2012 04:02 |
Peter Zeltins Messages: 8 Registered: July 2012 |
Junior Member |
|
|
Here, I have one more interesting exception thrown at startup of Tomcat container:
Caused by: java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:810)
at java.util.HashMap$KeyIterator.next(HashMap.java:845)
at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1026)
at org.eclipse.persistence.jpa.jpql.parser.JPQLQueryBNF.buildIdentifiers(JPQLQueryBNF.java:175)
at org.eclipse.persistence.jpa.jpql.parser.JPQLQueryBNF.populateIdentifiers(JPQLQueryBNF.java:449)
at org.eclipse.persistence.jpa.jpql.parser.JPQLQueryBNF.getExpressionFactory(JPQLQueryBNF.java:260)
at org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parseSingleExpression(AbstractExpression.java:1003)
at org.eclipse.persistence.jpa.jpql.parser.JPQLExpression.parse(JPQLExpression.java:307)
at org.eclipse.persistence.jpa.jpql.parser.JPQLExpression.<init>(JPQLExpression.java:129)
at org.eclipse.persistence.jpa.jpql.parser.JPQLExpression.<init>(JPQLExpression.java:91)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:258)
Weird. I wonder if this problem is Spring-related?
[Updated on: Fri, 27 July 2012 14:25] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03596 seconds