0
看来我的类没有被JPA的基础结构找到。我猜春天不能找到它?我已经试过包扫描并将类添加到persistence.xml。那里的任何人都有什么想法可以尝试让我的选择找到该类(和基础表)? 谢谢!未能找到类 - Spring 3,Hibernate 3,JPA
这是代码。
的persistence.xml
<persistence-unit name="myApp" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:joss/datasources/myDB</jta-data-source>
<!-- get a special error with this in - see below -->
<!-- <class>com.src.dao.User</class> -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.archive.autodetection" value="class,hbm" />
UserDAO的代码导致错误:时抛出
final String queryString="select model from " +User.class.getSimpleName() + " model where model."propertyName+"=:propertyValue";
return getJpaTemplate().executeFind(new JpaCallback() {
@Override
public Object doInJpa(EntityManager em) throws PersistenceException {
//this line causes the error below
Query query = em.createQuery(queryString);
错误:
201-06-10 18:59:32,736 ERROR [UserDAO] find by property name failed
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [select model from User model where model.value= :propertyValue]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException:User is not mapped [select model from User model where model.value= :propertyValue]
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:286)
的applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="com.src.dao" />
也尝试过一个bean中
<beans:bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" packagesToScan="com.src.dao">
<beans:property name="persistenceUnitName" value="myApp" />
<beans:property name="packagesToScan" value="com.src.dao" />
</beans:bean>
用户类别:
package com.src.dao
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
/**
* User Entity
*
* @author MyEclipse Persistence Tools
*/
@Entity
@Table (name="USERS", schema="myDb")
public class User extends AbstractUser implements java.io.Serializable, Comparable<User> {
添加类persistence.xml中:
When I add in <class> to my persistence.xml I get the following on app deploy. The war never deploys:
Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/configs/spring/stu-hibernate.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: myApp] Unable to build EntityManagerFactory
at org.springframework.beans.factory.annotation.AutoWiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
发布堆栈跟踪。 –