Hibernate version:
2.1.3
Mapping documents:
Code:
<hibernate-mapping default-cascade="none" auto-import="true">
<class name="com.Data" table="TEST_TIMESTAMP" >
<id name="id" type="string" column="ID" unsaved-value="null">
<generator class="assigned" />
</id>
<timestamp column="LAST_UPDATE" name="lastUpdate"/>
<property name="data" type="string" column="DATA" not-null="false" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Data data = (Data)session.load(Data.class,"1");
// Value coming from presentation layer
data.setData("");
session.flush();
Full stack trace of any exception that occurs:Name and version of the database you are using:Oracle 9.2.0.3
The generated SQL (show_sql=true):Code:
Hibernate: select data0_.ID as ID0_, data0_.LAST_UPDATE as LAST_UPD2_0_, data0_.DATA as DATA0_ from TEST_TIMESTAMP data0_ where data0_.ID=?
Hibernate: update TEST_TIMESTAMP set LAST_UPDATE=?, DATA=? where ID=? and LAST_UPDATE=?
Debug level Hibernate log excerpt:Code:
16:10:32,121 DEBUG Loader:197 - processing result set
16:10:32,121 DEBUG Loader:405 - result row: 1
16:10:32,121 DEBUG Loader:536 - Initializing object from ResultSet: 1
16:10:32,137 DEBUG Loader:605 - Hydrating entity: com.Data#1
16:10:32,168 DEBUG TimestampType:68 - returning '10 septembre 2004 15:58:15' as column: LAST_UPD2_0_
16:10:32,168 DEBUG StringType:64 - returning null as column: DATA0_
16:10:32,183 DEBUG SessionImpl:1899 - Version: 2004-09-10 15:58:15.0
16:10:32,183 DEBUG Loader:226 - done processing result set (1 rows)
...
16:10:39,527 DEBUG AbstractEntityPersister:274 - com.Data.data is dirty
16:10:39,527 DEBUG SessionImpl:2522 - Updating entity: [com.Data#1]
16:10:39,543 DEBUG Versioning:26 - Incrementing: 2004-09-10 15:58:15.0 to 2004-09-10 16:10:39.527
Hi,
this is quite an obvious problem but it has a great impact on our application because we already have a lot of code and mappings.
An object containing a null property is returned from the database and then presented into a browser page.
If the text field corresponding to the property is empty, the property is updated with an empty string (instead of null).
The dirty checking detects a change and then increments the version (which I think is legitimate).
This means trouble for us because there is a very strict control on database changes and it can also affect optimistic concurrency because the row is considered as changed even if the data is the same since for tha database the empty string is stored as NULL.
Is there some "low cost" workaround to that ?
My idea is to subclass StringType and change the equals method to implement null = "". Then we can probably substitute the type of each property dynamically at session factory creation.
What would be the impact of that ?
I understand that the clean way would be to set the property to null but we can't afford that change right know.
Any suggestion would be greatly appreciated.
Daniel