-->
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.  [ 1 post ] 
Author Message
 Post subject: Current Timestamp for Update fields
PostPosted: Tue Oct 02, 2007 12:03 pm 
Newbie

Joined: Thu Dec 30, 2004 3:51 pm
Posts: 14
Hi -

I have a database table with a create date and a update date. For any update statement to the table, i want to update the UPDATE_TSP field with the CURRENT TIMESTAMP from the database.

This table is a 1-to-1 with a parent table, so the id is generated by the parent table.

I tried using <timestamp> tag, but it would always try to do an insert for saveOrUpdate calls when it should be updating, and thus toss a duplicate key exception.

The work around below using <sql-update> works, but seems to me not a good design since changing the order or modifying the properties for the fields will make the custom SQL fail.

Is there a better way to accomplish this?

Thanks

Hibernate version:
3.2.3.ga
DB2 8.2

Mapping documents:
<class name="Stuff" table="STUFF">

<id name="pid" column="P_ID" type="long">
<generator class="assigned" />
</id>

<property name="name" column="NAME" type="string" />
<property name="number" column="NUMBER" type="long" />
<property name="weight" column="WEIGHT" type="double" />
<property name="createDate" column="CREATE_TSP" type="java.util.Date" generated="insert" update="false" />
<property name="updateDate" column="UPDATE_TSP" type="java.util.Date" generated="always" />

<sql-update>update STUFF
set NAME = ?,
NUMBER = ?,
WEIGHT = ?,
UPDATE_TSP = current timestamp,
where P_ID = ?
</sql-update>
</class>


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

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.