-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: filtering update queries
PostPosted: Fri Jul 25, 2008 10:33 am 
Newbie

Joined: Fri Jul 25, 2008 6:07 am
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 10:39 am 
Newbie

Joined: Fri Jul 25, 2008 6:07 am
Posts: 3
Sorry, this post should be in Java forum. Please, delete.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.