Roberto de Santis
Roberto de Santis

Reputation: 858

Hibernate update with default value

after some research i haven't found a solution. I need a query like this in Hibernate:

UPDATE table_name SET field=DEFAULT

it's possible to instruct hibernate to generate that query when I need to generate database default value on an update?

I have already try setting insert="false" and update="false", but this work only for insert query, when I perform an update simply hibernate doesn't set the field annotated with update="false".

Thank you in advance

Upvotes: 2

Views: 893

Answers (1)

Andrew Lazarus
Andrew Lazarus

Reputation: 19292

There is probably some much better sequence to get to the default value but I'm rusty on Hibernate.

PersistentClass pClass 
    = configuration.getClassMapping(yourJavaClass.class.getName());
Column col = pClass.getTable(getColumn("Column Name in Table"));

Now you can use col.getDefaultValue() and replace nulls with it.

Upvotes: 1

Related Questions