关于hibernate的annotation和配置文件
在看视频学hibernate,不知道最近企业用这两个方面哪个多一点,视频里说,主要用annotation,想请教请教大家 hibernate annotation
[解决办法]
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="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.current_session_context_class">thread</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.core.mvc.po.Student</value>
<value>com.core.mvc.po.Teacher</value>
<value>com.core.mvc.po.Comment</value>
<value>com.core.mvc.po.Department</value>
<value>com.core.mvc.po.Employee</value>
把要用大实体类写在这里
</list>
</property>
</bean>
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Column(name = "USERNAME", unique = true, nullable = false, length = 20)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "FULLNAME", nullable = false, length = 20)
public String getFullname() {
return this.fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
@Column(name = "PASSWORD", nullable = false, length = 20)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "DEPID", nullable = false, length = 50)
public String getDepid() {
return this.depid;
}
public void setDepid(String depid) {
this.depid = depid;
}
@Column(name = "LOCKED", nullable = false, length = 1)
public String getLocked() {
return this.locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
@Column(name = "CHANGEPASSWORD", nullable = false, length = 1)
public String getChangepassword() {
return this.changepassword;
}
public void setChangepassword(String changepassword) {
this.changepassword = changepassword;
}
@Column(name = "DUTYID", length = 50)
public String getDutyid() {
return this.dutyid;
}
public void setDutyid(String dutyid) {
this.dutyid = dutyid;
}
@Column(name = "MOBILE", length = 20)
public String getMobile() {
return this.mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
@Column(name = "SEX", length = 2)
public String getSex() {
return this.sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Column(name = "PHONEWORK", length = 20)
public String getPhonework() {
return this.phonework;
}
public void setPhonework(String phonework) {
this.phonework = phonework;
}
@Column(name = "PHONEHOME", length = 20)
public String getPhonehome() {
return this.phonehome;
}
public void setPhonehome(String phonehome) {
this.phonehome = phonehome;
}
@Column(name = "EMAIL", length = 100)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "ENTRUST", length = 50)
public String getEntrust() {
return this.entrust;
}
public void setEntrust(String entrust) {
this.entrust = entrust;
}
@Column(name = "STYLE", length = 50)
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
@Column(name = "KEYNUM", length = 50)
public String getKeynum() {
return keynum;
}
public void setKeynum(String keynum) {
this.keynum = keynum;
}
@Column(name = "KEYPAS", length = 50)
public String getKeypas() {
return keypas;
}
public void setKeypas(String keypas) {
this.keypas = keypas;
}
@Column(name = "BACKUP1", length = 100)
public String getBackup1() {
return backup1;
}
public void setBackup1(String backup1) {
this.backup1 = backup1;
}
@Column(name = "BACKUP2", length = 100)
public String getBackup2() {
return backup2;
}
public void setBackup2(String backup2) {
this.backup2 = backup2;
}
@Column(name = "BACKUP3", length = 100)
public String getBackup3() {
return backup3;
}
public void setBackup3(String backup3) {
this.backup3 = backup3;
}
@Column(name = "BACKUP4", length = 100)
public String getBackup4() {
return backup4;
}
public void setBackup4(String backup4) {
this.backup4 = backup4;
}
@Column(name = "BACKUP5", length = 100)
public String getBackup5() {
return backup5;
}
public void setBackup5(String backup5) {
this.backup5 = backup5;
}
}
[解决办法]
建议用Annotation 舒服