steve wrote:
with Hibernate 3.1, the easier approach is to simply use the generated timestamp values specifying that hibernate should use the db-generated values:
What if I want every possible case from my application within the same table:
* assign NULL
* assign explicitly
* SQL server generated with CURRENT_TIMESTAMP()
* SQL server generated with MY_FOO_DATE_FUNC()
I really would like to see a nuts and bolts interface for partial INSERT/UPDATE operations, this would allow me to use Hibernate for all data operations.
Call it a gloryfied statement builder if you like by based around object mappings / HSQL.
If you have the infrastructure in place to be able to do timestamps in 3.1 and make Hibernate realise that it needs to read back its value if the application touches it, then would it not be possible to extend the same mechnism to any column on a per-execution basis.
Allowing partial INSERTs to read back generated default values.
Allowing partial UPDATEs where the metadata could specify against each column if the SQL server if performing any magic on that column value on every update, or just on NULL assignment, or just on application given function litteral at the next statement execution.
Thinking about it some more, maybe another possible way to implement this API cleanly is from a new API call that could instate a detached object through a proxy. This proxy was able to mark each column as being touched or not.
This would allow the object to become attached during save() or update(), where as my fake peudo-code above would always keep the object detached, since the myObject instance is not magic, its the real concrete version with partially loaded values.
Code:
MyObject obj = hsession.instateDeatchedInstance(MyObject.class);
obj.setMyValueOne(1);
obj.setMyValueTwo(null);
hsession.save(obj);
long id = obj.getId();
// This generates a partial insert like:
// INSERT INTO my_object SET id=IDENTITY, my_value.one=1, my_value_two=NULL;
// even though the table has other columns, maybe like my_value_three
// During this property lookup hibernate would lazy re-load the generated value
System.out.println("my_value_three = " + obj.getMyValueThree());
Thanks for your input, this will sort me out for a number of cases where the value is always assigned with CURRENT_TIMESTAMP().