我正在使用 hibernate 4.1.5.Final 和 Spring 3.1.2 Release 和 Jboss 7.1 。我已经用 @NamedQuery 注释在一个类中编写了所有命名查询,但实体管理器没有创建命名查询。我正在发布堆栈跟踪和 context.xml
09:58:49,695 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) java.lang.IllegalArgumentException: Named query not found: validateLoginHash
09:58:49,770 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:642)
09:58:49,772 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
09:58:49,774 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
09:58:49,777 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at java.lang.reflect.Method.invoke(Method.java:597)
09:58:49,779 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
09:58:49,782 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at $Proxy30.createNamedQuery(Unknown Source)
09:58:49,784 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
09:58:49,785 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
09:58:49,788 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at java.lang.reflect.Method.invoke(Method.java:597)
09:58:49,790 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
09:58:49,793 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at $Proxy30.createNamedQuery(Unknown Source)
应用程序上下文.xml
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect"/>
<property name="packagesToScan" value="com.project.entities"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
<!-- <property name="persistenceUnitName" value="Project" /> -->
<property name="persistenceXmlLocation" value="classpath:META-INF/jpa-persistence.xml"/>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/MySqlDS"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
jpa-persistence.xml
<persistence>
<persistence-unit name="Project" transaction-type="RESOURCE_LOCAL" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:jboss/datasources/MySqlDS</non-jta-data-source>
<!-- <properties> -->
<!-- <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" /> -->
<!-- </properties> -->
</persistence-unit>
</persistence>
DBNamedQuery.java
@Entity
@NamedQueries( {
@NamedQuery(name = ... , query = ... ),
@NamedQuery(name = ..., query = ...),
.....More named queries
})
public class DBNamedQuery {
}