若之前使用的是.hbm.xml方式映射配置的spring,改为注解式方法时,需要修改持久类和sping的配置文件applicationContext.xml
1.持久化类
package com.zj.entity;
import javax.persistence.Basic;import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="SSH")
public class Ma {
private String userID;
private String userPassword;
public Ma() {
}
@Id
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
@Basic
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
}
2.applicationContext.xml
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!--指明使用标志的实体类-->
<property name="annotatedClasses">
<list>
<value>com.zj.entity.Ma</value>
</list>
</property>
<!-- <property name="mappingLocations" value="classpath:com/zj/entity/*.hbm.xml"></property>-->//该句是使用.hbm.xml方式时,使用的语句
</bean>