hibernate 为什么可以发出insert语句,却不能完全保存到数据库呢?

1、Customer类

public class Customer implements java.io.Serializable {

 // Fields

 private long customerId;
 private String customerName;
 private String customerNumber;
 private Integer creditGrade;
 private String customerAddress;
 private String phoneNumber;
 private String email;
 private String certificate;
 private String merchandisePlanning;
 private String checkState;
 private byte customerGender;
 private String checkinMan;
 private String remark;
 private Set applications = new HashSet(0);

......

 

2、Customer.hbm.xml

<hibernate-mapping>
    <class name="MPDMS.persistence.Customer" table="customer" schema="dbo" catalog="MPDMS">
        <id name="customerId" type="long" unsaved-value="null">
            <column name="customerId" precision="6" scale="0" />
            <generator class="native" />
        </id>
        <property name="customerName" type="string">
            <column name="customerName" length="20" />
        </property>
        <property name="customerNumber" type="string">
            <column name="customerNumber" length="15" />
        </property>
        <property name="creditGrade" type="integer">
            <column name="creditGrade" />
        </property>
        <property name="customerAddress" type="string">
            <column name="customerAddress" length="100" />
        </property>
        <property name="phoneNumber" type="string">
            <column name="phoneNumber" length="20" />
        </property>
        <property name="email" type="string">
            <column name="email" length="50" />
        </property>
        <property name="certificate" type="string">
            <column name="certificate" length="30" />
        </property>
        <property name="merchandisePlanning" type="string">
            <column name="merchandisePlanning" length="250" />
        </property>
        <property name="checkState" type="string">
            <column name="checkState" length="10" />
        </property>
        <property name="customerGender" type="byte">
            <column name="customerGender" />
        </property>
        <property name="checkinMan" type="string">
            <column name="checkinMan" length="20" />
        </property>
        <property name="remark" type="string">
            <column name="remark" length="256" />
        </property>
        <set name="applications" inverse="true">
            <key>
                <column name="customerId" precision="6" scale="0" not-null="true" />
            </key>
            <one-to-many class="MPDMS.persistence.Application" />
        </set>
    </class>
</hibernate-mapping>
.......

 

3、CustomerDao

 public void save(Customer transientInstance) {
  log.debug("saving Customer instance");
  try {
   Transaction tran = getSession().beginTransaction(); //方法2
   getSession().save(transientInstance);
   tran.commit();
   log.debug("save successful");
  } catch (RuntimeException re) {
   log.error("save failed", re);
   throw re;
  }
 }

4  CustomerTest

 public void testNewCustomer2() {
  CustomerDAO dao = new CustomerDAO();
  Customer customer = new Customer();
  customer.setCustomerName("姓名4");
  customer.setCustomerAddress("地址4");
  dao.save(customer);
  dao.getSession().flush();
  System.out.println("/n换行/n");
 }

 

执行改测试方法后,后台有发出插入语句

Hibernate: insert into MPDMS.dbo.customer (customerName, customerNumber, creditGrade, customerAddress, phoneNumber, email, certificate, merchandisePlanning, checkState, customerGender, checkinMan, remark) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

换行

 

可是,为什么sql server里面的数据没有刚刚插入的语句的?

 

非常奇怪!

 

现在问题解决了,可是是很奇怪的结果。

第二天我重新打开数据库,昨晚发出的sql语句,现在竟然能够更新到数据库了。

 

刚刚我再试一下发出新建记录,数据库还是没有变化,可是一旦sql server断开连接,然后重新连接打开后,数据就有更新了。

那是不是说明sql server更新得比较慢呢?

哎。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值