Issue Details (XML | Word | Printable)

Key: HHH-1491
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Renat Yusupov
Votes: 6
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

wrong set size() with lazy="extra" and where="..."

Created: 16/Feb/06 01:06 AM   Updated: 14/Apr/09 10:39 AM
Component/s: core
Affects Version/s: 3.1.2
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Text File AbstractCollectionPersister.patch (0.9 kB)
2. Java Archive File HHH1491.jar (16 kB)

Issue Links:
Relates
 

Bug Testcase Reminder (view):
REMINDER: Bug reports should generally be accompanied by a test case
Participants: Dan McGee, Renat Yusupov and Stefan Fleiter


 Description  « Hide

In mapping file if set lazy = "extra" to set and additionaly set some "where" attribute we have wrong size() returned if collection does not initalized. sql query just ignore additional where clause.
example:

Collection children = parent.getChildren();

System.out.println("Result = "+children.size());

for ( Iterator iter = children.iterator(); iter.hasNext(); )

{ //skip }

System.out.println("Result = "+children.size());

first result is greater that second.

part of mapping:
<set name="children" inverse="true" lazy="extra" where="system='f'">

if we use lazy="true" all ok.



Stefan Fleiter added a comment - 14/Mar/06 06:36 AM

HHH1491.jar is a minimal TestCase for this Bug.

After adjusting hibernate.cfg.xml, Album.hbm.xml and Image.hbm.xml to
your database you have to generate the schemata with hbm2ddl.
Then simply run HHH1491Test.

The test shows, that a collection mapped with lazy="extra" and a where condition reports
the wrong size until the collection is initialized.
I suppose the fix would be to append the where condition to the "select count(ID)" statement
which is generated to get the size of the collection without initializing it.


Stefan Fleiter added a comment - 14/Mar/06 08:09 AM

AbstractCollectionPersister.patch fixes the bug.
generateSelectSizeString() did not take into account the where condition
of the mapped collection.

I've used simpleSelect.addCondition("", sqlWhereString) since
SimpleSelect#add is private and SimpleSelect#addCondition(String)
does not exist.


Dan McGee added a comment - 14/Apr/09 10:39 AM

This is still not working for where clauses, and it appears the SQL generated for count queries also does not respect <filter> or @Filter statements in addition to the where clause documented here and in HHH-3319.