In Hibernate 3.0, isn't there a way to not include a property
at runtime (e.g. when this property is NULL in our app) so the value is set by the database default value and then the persistent object is updated with the generated value (like for the ID) ?
I've got the following default value for a "date" column in my database (timestamp in Hibernate mapping):
Code:
TO_DATE('3112' || TO_CHAR(SYSDATE, 'YYYY'), 'DDMMYYYY')
... and as the column is NOT-NULL, I'd like that Hibernate exclude this column/property/mapping from the INSERT or UPDATE statements IF the transient object property is NULL.
I tried the following mapping without success:
Code:
<property name="myDate" type="timestamp">
<column name="MY_DATE" not-null="true"
default="TO_DATE('3112' || TO_CHAR(SYSDATE, 'YYYY'), 'DDMMYYYY')" />
</property>
Either I get the following Hibernate exception:
Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.mycompany.somepackage.model.MyObject.myDate
... or if I set
not-null="false" , I get the SQL exception:
Code:
org.hibernate.util.JDBCExceptionReporter | ERROR | ORA-01400: cannot insert NULL into ("SCHEMA"."T_MY_TABLE"."MY_DATE")
How can I solve this...?
Cheers,
Maxx