开发者

Hibernate : how to configure the Flush after every RW-D operation?

开发者 https://www.devze.com 2022-12-16 20:09 出处:网络
I have an AbstractDao implemented by every Dao of my database. public abstract class AbstractDaoI开发者_如何学运维mpl extends HibernateDaoSupport {

I have an AbstractDao implemented by every Dao of my database.

public abstract class AbstractDaoI开发者_如何学运维mpl extends HibernateDaoSupport {

(...) public void delete(T pEntity) throws FerdeDaoException {

    try {
        this.getHibernateTemplate().delete(pEntity);
    } (...)
}

....

Bascially the flushMode seems to be at AUTO.

What do i want ?

I want to be sure that when this class is use in unit test, I want to have a flush after every basic operation (delete, update, save) with this class above.

What is a solution ?

i think i would have to add after the line : this.getHibernateTemplate().delete(pEntity) in the method above

this one : this.getHibernateTemplate().flush() only for my unit test.

But i cant add it directly in the AsbtractDao because it is used in other project where the flush will be done automatically.

Or do i have nothin to add because the AUTO flushmode flush after every DELETE/SAVE/UPDATE operation ?? ( i dont have read that ine the javadoc).

Thanks in advance for your anwser.


Nice one :)

Why you don't specify a system variable, that specifies the mode of operation of your application. for example:

-DrunningMode=test -DrunningMode=development -DrunningMode=production

and based on your runningMode system variable you can decide what to do in your AbstractDAO, or you can set the property of AUTO flush for testing to true, and for non testing environments to false, and use different configurations when running in different modes.

If you are using this class in different projects, may be it is better that you back it with a configuration file that will instruct this class how to work. (XML or .properties)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号