开发者

Create NHibernate created on column depending on the version column

开发者_运维技巧I'm trying to create a created_on column - this column should store the date and time of the row creation.

I'm also using a Version Column - a column that holds the last update time of the record, this comes with Nhibernate.

What I want to do is to copy the version column value to the created_on column when the row gets inserted to the db. Meaning, if version is modified and the entity is new (we are pre-flushing) I need to put the value of the version column inside the created_on column and that's it.

So far I managed only to do it with an extra update after the insert using a interceptor and overriding PreFlush.

I'm working with Nhibernate 3 with Oracle Any suggestions?


I don't know anything about Nhibernate, but... as far I can understand... why you don't use a database trigger? An after insert trigger.

Or, more simply(or too simply), you can create the created_on column with default value sysdate.


It sounds like you are using "DB Timestamp" versioning. Can you use normal timestamp instead? This becomes trivial if you are setting the values in code.

Another alternative is to set up your created on column as immutable (read-only) and using a database level default of CURRENT_TIMESTAMP. This should give you the same value in both columns on an insert, if I am correct that you are using the DB to set the version column.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜