2011-12-08 48 views
1

CustomerType實體:髒讀處於休眠

public class CustomerType implements java.io.Serializable { 

private Integer customerTypeId; 
private String customerDesc; 
private Set customerInfos = new HashSet(0); 

public CustomerType() { 
} 

public CustomerType(String customerDesc) { 
    this.customerDesc = customerDesc; 
} 

public CustomerType(String customerDesc, Set customerInfos) { 
    this.customerDesc = customerDesc; 
    this.customerInfos = customerInfos; 
} 

public Integer getCustomerTypeId() { 
    return this.customerTypeId; 
} 

public void setCustomerTypeId(Integer customerTypeId) { 
    this.customerTypeId = customerTypeId; 
} 
..................... 

CustomerType有一個與此實體一對多關係

public class CustomerInfo implements java.io.Serializable { 

private Integer customerId; 
private CustomerType customerType; 
private String name; 
    ................................. 

我有一個這種方法在DaoImpl類

@Override 
public int save(Object object) { 
    try{ 
     transaction = session.beginTransaction(); 
     session.saveOrUpdate(object); 
     session.flush(); 
     transaction.commit(); 
     return 1; 
    }catch (Exception e) { 
     transaction.rollback(); 
     e.printStackTrace();// TODO: handle exception 
     return 0; 
    } 
} 

和我在更新對象時稱它爲

public String updateCustomerType(){ 
    this.customertype = this.daoManager.findCustoType(Integer.parseInt(this.customerTypeID)); 
    this.customertype.setCustomerDesc(this.custoTypeDesc); 
    this.daoManager.save(this.customertype); 
} 

這種方法成功地更新數據庫,但是當我顯示CustomerInfo的列表,它有關係CustomerType,在CustomerInfo的CustomerType參數不udpated

org.hibernate.Query q = session.createQuery("select customerInfo from CustomerInfo customerInfo"); 
return q.list(); 

有什麼錯我的。,等待您的評論。謝謝,

+0

等待您的解決方案, –

+0

真的在等待你的解決方案。 –

回答

0

我相信你的問題是你想讀取未提交的數據。

我沒有測試過這對您的特定問題,但你可以嘗試:

session.connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); 

而且下面有一個極好的堆棧,以幫助解釋進一步read_uncommited:

Why use a READ UNCOMMITTED isolation level?