spring_hibernate.xml
<!-- spring和 Hibernate整合 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="myeclipse.connection.profile">MyEclipse MySQL</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- 注解写法 -->
<property name="annotatedClasses" >
<list>
<value>com.ssh.entity.SimpleProfessional</value>
</list>
</property>
</bean>
SimpleProfessional实体类
package com.ssh.entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
/**
* Professional entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name="professional",catalog="oa")
public class SimpleProfessional implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = 9008124251016810039L;
private Integer professionalId;
private String professionalName;
private Date professionalDate;
// Constructors
/** default constructor */
public SimpleProfessional() {
}
public SimpleProfessional(Integer professionalId, String professionalName) {
super();
this.professionalId = professionalId;
this.professionalName = professionalName;
}
/** full constructor */
public SimpleProfessional(String professionalName, Date professionalDate) {
this.professionalName = professionalName;
this.professionalDate = professionalDate;
}
// Property accessors
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GenericGenerator(name = "professionalGenerator", strategy = "native")
@Column(name="professional_id")
public Integer getProfessionalId() {
return this.professionalId;
}
public void setProfessionalId(Integer professionalId) {
this.professionalId = professionalId;
}
@Column(name="professional_name")
public String getProfessionalName() {
return this.professionalName;
}
public void setProfessionalName(String professionalName) {
this.professionalName = professionalName;
}
@Column(name="professional_date",length=10)
public Date getProfessionalDate() {
return this.professionalDate;
}
public void setProfessionalDate(Date professionalDate) {
this.professionalDate = professionalDate;
}
@Override
public String toString() {
return "Professional [professionalId=" + professionalId
+ ", professionalName=" + professionalName
+ ", professionalDate=" + professionalDate + "]";
}
}