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