我得到異常Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Building is not mapped [from Building]
我的建築類映射的實體未映射
@javax.persistence.Entity
@Table(name = "building")
public class Building extends AbstractModel {
AbstractModel是空的(只是向上轉型)
設置packagesToScan
@Primary
@Bean
@Autowired
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
....
localContainerEntityManagerFactoryBean.setPackagesToScan("com.app.persistence.model");
....
}
代碼拋出EXCETION
public <M extends AbstractModel> List<M> findAll() {
List<Building> buildings;
try {
buildings = (List<Building>) getHibernateTemplate().find("from Building");
} catch (Exception e) {
throw e;
}
return (List<M>) buildings;
}
而且我setuped
@Bean
public LocalSessionFactoryBean localSessionFactoryBean(DataSource ds) throws ClassNotFoundException {
LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
localSessionFactoryBean.setDataSource(dataSource());
return localSessionFactoryBean;
}
看起來像'Building'類本身或'AbstractModel'有問題。很難說,許多細節被省略 – Andremoniy
爲什麼要配置一個JPA EntityManagerFactory,但開始使用普通的Hibernate?您還需要相應地設置'SessionFactory'(儘管我會建議僅使用JPA而不是簡單的休眠)。 –
你使用javax.persistence.Table or org.hibernate.annotations.Table嗎? –