当前位置: 代码迷 >> J2EE >> org.springframework.orm.hibernate3.HibernateSystemException: Unknown
  详细解决方案

org.springframework.orm.hibernate3.HibernateSystemException: Unknown

热度:376   发布时间:2016-04-22 03:07:43.0
要崩溃了,使用hibernate的annotation进行实体映射,找不到实体,求解
实体类
package org.test.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "back")
public class Back implements java.io.Serializable {

/**

*/
private static final long serialVersionUID = 970929164209819495L;
/**

*/
private Integer id;

public Back() {
}

public Back(Integer id) {
this.id = id;
}

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}
}

application.xml配置文件
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">
true
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.proxool.xml">proxool.xml</prop>
<prop key="hibernate.proxool.pool_alias">DBPool</prop>
</props>
</property>
<!-- <property name="mappingResources">
<list>
<value>org/test/entity/Back.hbm.xml</value>
</list>
</property>-->
<property name="packagesToScan" value="org.test.entity.*" />
</bean>


dao文件

package org.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.dao.HibernateBaseDao;

public class HibernateBaseDaoImpl extends HibernateDaoSupport implements
HibernateBaseDao {

 
public Object getEntityById(Class clazz, Integer id) {
return getHibernateTemplate().get(clazz, id);
}

public boolean saveOrUpdate(Object o) {
getHibernateTemplate().save(o);
return false;
}

}

一执行dao里的方法就报如下错误

org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: org.test.entity.Back; nested exception is org.hibernate.MappingException: Unknown entity: org.test.entity.Back
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)


------解决方案--------------------
探讨
<value>org/test/entity/Back.hbm.xml </value>

既然是注解,为什么还会出现映射配置文件??

给个例子:

XML code<!-- 使用Annotation映射的sessionFactory--><beanid="sessionFactory"
  相关解决方案