package com.bjdv.module; |
import org.hibernate.Session; |
import org.hibernate.SessionFactory; |
import org.hibernate.cfg.Configuration; |
import org.junit.Test; |
/** |
* Project:hibernateTest <br> |
* Module: <br> |
* Description: <br> |
* Version:1.0 <br> |
* Date:2013-8-3 <br> |
* Copyright (C) 2013 <br> |
* |
* @author:beijing_qi |
*/ |
public class StaffTest { |
|
@Test |
public void testSaffUpdate(){ |
|
Configuration c= new Configuration(); |
SessionFactory f=c.configure().buildSessionFactory(); |
Session session=f.openSession(); |
session.beginTransaction(); |
//调用get方法,先检查缓存中是否有改记录,如果没有发出一条select语句,从数据库中读取 |
Staff s=(Staff)session.get(Staff. class , 1 ); |
//当set改变某个属性值时,判断是否与缓存中的记录相同,如果不同才进行更新缓存和数据库中的记录 |
s.setStaff_name( "testZhang" ); |
session.getTransaction().commit(); |
session.close(); |
f.close(); |
|
} |
} |