2013-06-20 52 views
0

我有和Hibernate的問題,我試圖保存和實體通過和抽象Dao類,它似乎不想保存或更新,但我的刪除功能似乎工作完美無缺。所以我想知道是否有人能指出我似乎出錯的地方。抽象道不更新或保存與休眠

我做了調試,看看實體在更新或保存時是否完全加載到變量中。

在此先感謝您的任何想法。

在那裏我拉中的所有數據類:

 try{ 
     accountDao.add(newAccount); 
     return SUCCESS; 
    } 
    catch(Exception e){ 
     this.addActionError("And unknown error has occurred please try refreshing the page"); 
     return INPUT; 
    } 

都到這個Hibernate工具類,實體數據在參數傳遞到add函數被調用,但它只是似乎這Hibernate不會保存:

public abstract class AbstractDao<Entity> extends HibernateDaoSupport { 

    public void add(Entity entity) { 
     getHibernateTemplate().save(entity); 
    } 

    public void delete(Entity entity) { 
     getHibernateTemplate().delete(entity); 
    } 

    public abstract List<Entity> findAll(); 

    public abstract List<Entity> findById(Long id); 

    public void update(Entity entity) { 
     getHibernateTemplate().update(entity); 
    } 

} 

bean定義

<bean id="accountDao" class="com.dao.AccountDao"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

<bean id="utilityDao" class="com.dao.UtilityDao"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

<bean id="account_usageDao" class="com.dao.Account_UsageDao"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

    <bean id="addCustomerInfo" class="com.action.customer.AddAction" scope="prototype"> 
    <property name="accountDao" ref="accountDao"/> 
    <property name="utilityDao" ref="utilityDao"/> 
    <property name="account_usageDao" ref="account_usageDao"/> 
</bean> 

更新1:豆的定義

回答

0

我看不出更多的實現。看來你正在使用彈簧。當我忘記定義一個事務上下文時,這個問題通常發生在我身上。

看一看:Spring Transaction management

+0

感謝您的回答,我使用Spring,Hibernate的,Struts2的和我通過最上面寫着,我相信我給冬眠與我的bean定義一個適當的範圍內,但我會再探索一下這個領域。 – gcalex5

+0

指出我在正確的方向,我進一步調試它發現Hibernate受到日期根據我的catch語句被鑄造到字符串感到不滿,我發佈之前,我真的應該發現它。不過謝謝你! – gcalex5