-->
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: Computed Column Mapping
PostPosted: Fri Jul 13, 2007 4:26 pm 
Newbie

Joined: Mon Feb 06, 2006 2:03 pm
Posts: 2
Hi,

I am trying to map a property to a computed column. The column is computed on the DB.

I have tried setting both update/insert to false, but I get a "cannot be used in an IF UPDATE clause because it is a computed column." error after updating the entiy. I am assuming because the DB updates the value but hibernate can't figure out that the value has changed and needs to update it.

I have also tried setting the "formula" attribute on the property in my mapping to the same logic that my DB uses (simple case statement), but this return the same error when I try to update.

Here is my mapping with the formula attr:

Code:
      <property name="accurate" column="isAccurate" update="false" insert="false" formula="(CASE WHEN StatusID IN (2,3,4) THEN 0 ELSE 1 END)"/>         


Any ideas? Can hibernate handle columns computed by the DB? The DB is shared with other apps, so it is not possible for the logic to be taken out of the DB and just left to exist in my mapping.

Thx in advance,

James


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 5:54 am 
Newbie

Joined: Fri Dec 08, 2006 6:05 am
Posts: 2
Location: Belgium
Use the
Code:
generated="always"
attribute and drop the formula attribute since its not Hibernate who's calculating the value.

Be aware that after flushing, Hibernate will perform an additional select to retrieve the generated value from the database.

_________________
Jurgen Van Oosterwijck


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.