摘要Dao没有用Hibernate更新或保存

时间:2021-05-29 19:15:48

I'm having and issue with Hibernate where I'm trying to save and entity through and Abstract Dao class and it seems to not want to save or update however my delete functionality seems to work flawlessly. So I was wondering if someone could point out where I seem to be going wrong.

我有Hibernate的问题,我试图保存和实体通过和抽象Dao类,它似乎不想保存或更新,但我的删除功能似乎完美无缺。所以我想知道是否有人可以指出我似乎出错的地方。

I did debug to see that the entity is in-fact fully loaded into the variable when it goes to update or save.

我做了调试,看到实体在进行更新或保存时实际上已完全加载到变量中。

Thanks in advance for any ideas.

提前感谢任何想法。

The class where I'm pulling all the data in:

我正在提取所有数据的类:

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

Which goes to this hibernate utility class, the entity data is in the parameter being passed into the add function being called but it just seems that hibernate won't save it:

对于这个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 definition

<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>

Update 1: Bean definition

更新1:Bean定义

1 个解决方案

#1


0  

I can't tell without seeing more of the implementation. It appears you are using spring. This problem usually happens to me when I forget to define a transaction context.

没有看到更多的实施,我无法分辨。看来你正在使用弹簧。当我忘记定义事务上下文时,这个问题通常会发生在我身上。

Have a look at: Spring Transaction management

看看:Spring Transaction management

#1


0  

I can't tell without seeing more of the implementation. It appears you are using spring. This problem usually happens to me when I forget to define a transaction context.

没有看到更多的实施,我无法分辨。看来你正在使用弹簧。当我忘记定义事务上下文时,这个问题通常会发生在我身上。

Have a look at: Spring Transaction management

看看:Spring Transaction management