Hibernate Dao类 映射Class “Unknown entity” 急在线等~~!
使用SSH2
连接MySQL
数据库:
mysql> desc student;
+--------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+----------------+
| S_no | int(10) unsigned | NO | PRI | NULL | auto_increment |
| S_name | varchar(45) | NO | | NULL | |
| S_sex | varchar(45) | NO | | NULL | |
| S_age | varchar(45) | NO | | NULL | |
+--------+------------------+------+-----+---------+----------------+
实体类
@Entity
@Table(name="student",schema="test")
public class Student implements java.io.Serializable {
private String sNo;
private String sName;
private String sSex;
private String sAge;
public Student() {
}
public Student(String sName, String sSex, String sAge) {
this.sName = sName;
this.sSex = sSex;
this.sAge = sAge;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="S_no")
public String getSNo() {
return this.sNo;
}
public void setSNo(String sNo) {
this.sNo = sNo;
}
@Column(name="S_name")
public String getSName() {
return this.sName;
}
…………
……
spring配置文件
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
</props>
</property>
<property name="schemaUpdate" value="false"></property>
<property name="packagesToScan">
<list>
<value>org/workflow/entity/Student</value>
</list>
</property>
</bean>
其它的都没问题
就运行到 DAO类的时候调用
this.getHibernateTemplate().get()的时候
提示 Unknown entity: org.workflow.entity.Student
在 this.getHibernateTemplate() 之前 有输出
System.out.println(Student.class);
输出的内容是 :class org.workflow.entity.Student
请教,问题出在哪,spring 文件以前连接ORACLE的时候一直都是这样配置的没问题
这次用Mysql 的时候 就出错了,是不是忘了哪一步?
------解决方案--------------------实体BEAN的sNo属性是int还是String?
------解决方案--------------------Student 没有继承hibernatedaosupport,,
------解决方案--------------------那看看hbm映射是不是映射错了,别着急。
------解决方案--------------------