-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Taking advantage of Oracle's RETURNING clause
PostPosted: Wed May 10, 2006 5:55 pm 
Regular
Regular

Joined: Wed Feb 15, 2006 9:09 pm
Posts: 76
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.