-->
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.  [ 3 posts ] 
Author Message
 Post subject: subselect fetch fails after a delete
PostPosted: Thu Jul 27, 2006 12:43 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
Hibernate version: 3.1

Yesterday I started to use fetch="subselect" to solve an N+1 join problem I have with a report.. First of all, I would REALLY like to see this select style available as an override option so that it's not always on. That said, I ran into a problem...

I queried a set of entities by foreign key "from MyThing where user = :user".. Then I deleted the entities, and deleted the user. When the transaction committed, I got a failure. I believe it's do to the fact that MyThing has a collection of children who are set to be fetched via subselect. The collection is also cascade="all-delete-orphan"..

Since the JDBC exception is complaining a parameter was missing, it looks to me as if the user is now gone, and the subselect is invalid.

I suspect I can fix it in this case by join-fetching the relationship in my original HQL, but I'm afraid I'll be running into this again. Is this expected behavior?

Are there other pitfalls to using fetch="subselect" besides deletions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 2:17 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
A bit more information... I was wrong about my original assumption. I restructured the code so that the user wasn't deleted, and I still got the error.. in fact, I got it in Hibernate.initialize(mything.children())..

I debuged Hibernate, and the SubselectOneToManyLoader builds the query.. the queryParameters has the parameter for user, but only in it's namedParameters MAP.. The SubselectOneToManyLoader class-chain doesn't have an implementation of bindNamedParameters... and so the parameter isn't added, and the subselect fails.

I'm confused as to what's going wrong, though. There don't seem to be any implementations of Loader.bindNamedParameters() on this version. Is there a limitation of subselect fetching I'm missing? Is there something else I can look at that might help me understand what's happening here?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 3:31 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
Okay.. Solved my own problem, but for anyone else who finds this thread during their search... the bug is:

http://opensource.atlassian.com/project ... se/HHH-801


Subselects don't work at all for queries with named parameters. Fixed in 3.1 (despite my original post, I was using 3.0)...

So yeah. I'm a bonehead. Hopefully you've arrived at this post by doing a search instead of posting a new bonehead topic like I did :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.