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)
發佈堆棧跟蹤。 –