Hi all,
Thanks for your response so far.
We've been digging through the Hibernate code to see just how difficult this is going to be, and are unfortunately getting to the stage where us doing this is becoming less and less likely.
The reasons for this are that the two different broad methods we can think of to implement this are both quite hacky, complex and probably slow. I'll quickly describe them both as food for thought:
1. Running the HQL command as normal on the database, then inserting all records that are not part of the database into the list of retrieved records. This is OK in the most simple of cases, but it quickly becomes over complex in cases such as:
Code:
select foo.name from Foo as foo, Bar as bar where foo.name = bar.name
In this case, inserting a Foo type object that hasn't been commited yet would require a further database query to get all bar.name's before being able to decide whether the uncommited Foo belongs in the list. Add in a complex set of left joins and it is possible that each HQL query may require several more database queries. To us this looks too slow and complex to be of too much use, especially as we are often dealing with database tables with up to a few tens of thousands of rows.
2. The other solution thrown about was to commit any object that was currently in the Session, but not in the database in a new Session, execute the query on this new Session and then roll back the transaction. Adding the extra db transaction is not very appealing to us, and then there is the issue of locking the database while this occurs (so that no other concurrent db user gets the temporarily added records).
There are more holes with these approaches that many of you will be able to pick quite easily.
As I mentioned in my first post, being able to do this change will provide an elegant solution to a fairly large problem we have in our app -- but if the cost is too high we will need to put our developers on another uglier, but quicker, solution. If anyone can provide some guidance or suggestions on how to overcome the above problems so that we can justify making the modification to Hibernate please do post (or email if prefered).
Thanks again,
Luke