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.
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.