0
我是新来冬眠我写我的第一个休眠代码,我无法理解的输出与它的代码是:的Hibernate代码Understandig输出
持久类:
package com.andoi.hibernate;
public class Customers {
public int cid; //Primary key
public String cname;
public String email;
public long phone;
public Customers(){
System.out.println("Customers->dc");
}
public Customers(String cname,String email,long phone){
System.out.println("Customers->three arg");
this.cname=cname;
this.email=email;
this.phone=phone;
}
public int getCid() {
System.out.println("getCid()");
return cid;
}
public void setCid(int cid) {
System.out.println("setCid()");
this.cid = cid;
}
public String getCname() {
System.out.println("getCname()");
return cname;
}
public void setCname(String cname) {
System.out.println("setCname()");
this.cname = cname;
}
public String getEmail() {
System.out.println("getEmail()");
return email;
}
public void setEmail(String email) {
System.out.println("setEmail()");
this.email = email;
}
public long getPhone() {
System.out.println("getPhone()");
return phone;
}
public void setPhone(long phone) {
System.out.println("setPhone()");
this.phone = phone;
}
}
Hibernate映射文件:
<hibernate-mapping package="com.andoi.hibernate">
<class name="Customers" table="jlccustomers">
<id name="cid" column="cid" type="int">
<generator class="increment"/>
</id>
<property name="cname" column="cname" type="string"/>
<property name="email" column="email" type="string"/>
<property name="phone" column="phone" type="long"/>
</class>
</hibernate-mapping>
客户端代码:
package com.andoi.hibernate;
import org.hibernate.cfg.*;
import org.hibernate.*;
public class SaveInTable {
public static void main(String[] args){
Transaction tx=null;
try{
Configuration cfg=new Configuration();
cfg=cfg.configure();
SessionFactory sf=cfg.buildSessionFactory();
Session session=sf.openSession();
tx=session.beginTransaction();
}catch(HibernateException e){
if(tx!=null)
tx.rollback();
e.printStackTrace();
}
}
}
,并输出为:
Customers->dc
getCid()
Customers->dc
getCname()
getEmail()
getPhone()
setCname()
setEmail()
setPhone()
我的问题是,为什么在创建我的执着类对象和getter和setter方法被调用。