Hibernate version: 3.1.3
Name and version of the database you are using: Oracle 10gR2
Can I take advantage of the RETURNING clause in Oracle so Hibernate executes fewer queries (eliminating all SELECTs after INSERT/UPDATE for auto-generated columns)? If not, are there any plans to add support for this? Is this feasable?
Before discovering hibernate, I had a very rudimentary OR mapping in my Java code. Let's say I had a table with a primary key (test_id), and an audit column (update_time), both automatically generated through triggers. To round out the example, let's say I also had a value column ( test_value VARCHAR(32) ). I would create CallableStatements with something like the following:
Code:
CallableStatement stmt = con.prepareCall( "{call INSERT INTO test_table ( test_id, update_time, test_value ) VALUES ( ?, ?, ? ) RETURNING test_id, update_time INTO ?, ? }" );
Believe it or not this actually worked quite well... I'd end up doing something like the following:
Code:
stmt.registerOutParameter( 4, Types.NUMERIC );
stmt.registerOutParameter( 5, Types.TIMESTAMP );
stmt.setString( 1, null );
stmt.setString( 2, null );
stmt.setString( 3, testValue );
int insertCount = stmt.executeUpdate();
long pk = stmt.getLong( 4 );
Timestamp updateTime = stmt.getTimestamp( 5 );
The beauty is you have the tingly safe feeling of knowing the insert/update + synchronization routine is atomic... anyways, I wasn't sure if Hibernate supported this at all, hence the long explanation, and
16.4. Custom SQL for create, update and delete didn't provide me with any clues beyond the insert/update/delete count (which, incidentally, executeUpdate() properly returns in the above example).
Ideas?
Oooh and Annotations support would be neat too, though I'm not sure if this would provide any advantage beyond eliminating the mapping files in this case.