Hi folks,
I'm trying to leverage the default column values in my database through Hibernate, but I can't determine the right XML to use in my mapping file. Here's the situation.
The column
bar in the table
foo is defined as:
Code:
bar Enum('tic','tac','toe') NOT NULL DEFAULT 'tic'
As you can see, the column does not allow nulls and has a default value.
I have an object
foo, with
getBar() and
setBar(java.lang.String) methods. If I try to persist the object
foo when
foo.getBar() returns null, I want Hibernate to not send an explicit null for column
bar to the database. This would allow the database to set column
bar to value
'tic'.
Is it possible to configure this behavior in the Hibernate mapping file for table
foo? I have this property for column
bar:
Code:
<property name="bar" column="bar" type="java.lang.String" not-null="false" />
I checked the documentation and saw the
insert=false attribute for the property tag, but when I tried it
foo.setBar('toe') has no effect when
foo is persisted, meaning the column will always have value
'tic'.
Alternatively, a less desirable solution is for the Hibernate to explicitly send the default value
'tic' when
foo.getBar() returns null. I tried using the
Code:
<column name="bar" ... default="tic" />
tag to do this, but to no avail.
Can someone please shed some light on this issue? It would be very helpful to see a working XML snippet.
Thanks very much in advance,
mers