-->
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.  [ 12 posts ] 
Author Message
 Post subject: Request for advice from Hibernate developers
PostPosted: Fri Nov 07, 2003 2:08 am 
Newbie

Joined: Wed Sep 03, 2003 8:36 pm
Posts: 5
Location: Melbourne, Australia
Hi to all with some internal knowledge of Hibernate,

Our development team has found that it will be of some serious value to us if we could use the Session.find() method to not only query from the database, but from the current Session cache.

A simplified example of the situation we need to work follows:

Code:
Session session = ....
Session differentsession = .....

Transaction trans = session.beginTransaction();

Foo newFoo = new Foo();
newFoo.setId(10);
session.save(newFoo);

// need newFoo to be found here, even though we haven't committed the transaction yet
// we don't want newFoo to be present in the database however
List foolist = session.find("from Foo as foo where foo.id = ?", 10, Hibernate.LONG);

// newFoo shouldn't appear in otherfoolist
List otherfoolist = differentSession.find("from Foo as foo where foo.id = ?", 10, Hibernate.LONG);

trans.commit();


We were prepared to put some time and developer resources into this (i.e. we would be doing this ourselves in house). We also have an alternative solution which promises to be very painful to implement and much less neat than if the change to Hibernate we propose was implemented.

It has fallen to me to do some of the analysis for this over the next few days before we make the decision of which path to go down.

I was hoping that those of you that have had significant input in writing Hibernate could pass on your opinions of the feasability of making the above work. Is there anything intrinsic within the architecture of Hibernate that would make this particularly tricky to do? Any advice or pearls of wisdom that might make the decision easier would be much appreciated.

Thanks,
Luke.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 2:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you are trying to avoid phantom reads, why not just flip your JDBC connection to SERIALIZABLE isolation (assuming your database supports that).

Well, it would be quite difficult to implement for HQL queries, partly because its just difficult, and partly because the HQL parser does not yet work by creating an AST. So you would have to write a complete HQL parser (and write a proper grammar while you're at it). Now, if you wrote a working HQL -> AST parser for me, you would be my best friend for ever ... but that is not trivial.

OTOH, it looks quite easy to add to the Criteria query API, but don't expect to be able to do it in 2 days. It would take me at least three, I think. You longer, presumably.

However, remember that before I would accept anything like this into the Hibernate codebase, it would need to handle not just newly saved objects, but also updated objects, and also deleted objects. Now, I don't think that there are any special difficulties added by updates that don't exist for saves, but make sure you consider this.


Top
 Profile  
 
 Post subject: Did somebody say AST?
PostPosted: Fri Nov 07, 2003 7:13 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
Hmmm... a parser for Hibernate Query Language eh? I have some experience writing compilers (AST based), maybe I could help out. Is there some sort of BNF for HQL that I could take a look at? I suppose I could try to figure it out from the docos.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 7:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Here is the best I can give you ... probably broken, since I never tested it...


http://www.hibernate.org/Documentation/HQLBNF


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 9:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I was looking for this BNF the other day. I could not find the link from the documentation page. Maybe a stupid question but where is the link ? Can we also check to see what else has been dropped off the radar (if anything).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 9:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's linked on the "Community Area" index page. As far as I know, nothing has been lost, all is linked and (mostly) good.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 8:37 pm 
Newbie

Joined: Wed Sep 03, 2003 8:36 pm
Posts: 5
Location: Melbourne, Australia
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 4:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, good point, in cases like this it would actually slow the query down a great deal, wouldn't it. Interesting. This is a problem with the whole *notion* of queries done on the session cache, not just a design problem.

However, a case where it could work effectively is for queries with no joins. It is also easy to implement in this case ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 7:44 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
gavin wrote:
Here is the best I can give you ... probably broken, since I never tested it...


http://www.hibernate.org/Documentation/HQLBNF


Thanks. I've started working on an HQL grammar, and started a new topic in 'Misc' for this.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 9:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This should be discussed in the development list.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 9:56 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
gavin wrote:
This should be discussed in the development list.


Oh, okay "my bad". I guess I should subscribe to the development list. :")


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 10:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
:)


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

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.