views:

83

answers:

2

I have a domain class that when persisted to Oracle must update a column to sysdate. NHibernate must only generate 1 SQL. e.g.

update person set age = 12, stamp = sysdate where id = 1;

Can this be done?

EDITED:

Could be something like:

Person person = (Person)session.Get(typeof(Person), 1);
session.SetFunction(person, "stamp", Functions.CurrentTimestamp);
person.Age = 12;
session.Flush();
A: 

You could update the stamp via a database trigger:

create trigger person_trg
before update
for each row
begin
    :new.stamp := sysdate;
end;

Then all hibernate would need to do is "persist" the change to age (for example).

Tony Andrews
thanks, but i cannot use this solution. I want to control when the stamp is assigned from the code.
Wyass
A: 

If you want to do that on demand, you can just execute the query above:

session.CreateQuery("update person set age = 12, stamp = sysdate where id = 1")
       .ExecuteUpdate();

Interestingly, that is both valid HQL and SQL.

Diego Mijelshon
Also this is possible, but i rellay would like not to use sql/hql
Wyass