Version: Hibernate 3.2
Hi,
I'm trying to implement update query with conditions.
I want to see query like this:
Code:
UPDATE my_table SET ... WHERE my_column1=?
I could simply write this query as SQL, but I don't want to enumerate all columns in SET clause. I have about 50 columns and it will be hard to maintain. So, I'm seeking a way to apply condition on Session.update() query.
I've implemented filtering in my session, but during update, hibernate just ignores my condition.
Here is my mapping:
Code:
<class>
...
<property name="myColumn1" column="my_column1" not-null="true"/>
...
<filter name="myFilter" condition=":myFilterParam = my_column1"/>
</class>
<filter-def name="myFilter">
<filter-param name="myFilterParam" type="int"/>
</filter-def>
And using in java-code:
Code:
...
session.enableFilter("myFilter").setParameter("myFilterParam", obj.getIntCondition());
session.update(obj.getClass().getCanonicalName(), obj);
...
Update occurs in any case - hibernate just ignoring condition. I can see that in log where hibernate prints query.
I've searched trough this forum, but I saw that filters are used only for "select" queries (e.g. criteria.list()).
Is it possible to use filtering for update queries? If yes, why my code doesn't work? If no, how can I do this conditioned update?
Will appreciate any help.
Alexander.