I'm getting the following exception:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
[FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=net.iss.sp.entity.Asset.networkInterfaces,tableName=NetworkInterface,tableAlias=networkint1_,origin=Asset asset0_,colums={asset0_.AssetID ,className=net.iss.sp.entity.NetworkInterface}}]
[select count( asset ) from net.iss.sp.entity.Asset asset left join fetch asset.networkInterfaces left join fetch asset.owner left join fetch asset.criticality ];
nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
[FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=net.iss.sp.entity.Asset.networkInterfaces,tableName=NetworkInterface,tableAlias=networkint1_,origin=Asset asset0_,colums={asset0_.AssetID ,className=net.iss.sp.entity.NetworkInterface}}]
[select count( asset ) from net.iss.sp.entity.Asset asset left join fetch asset.networkInterfaces left join fetch asset.owner left join fetch asset.criticality ]
I've read the hibernate release notes:
http://www.hibernate.org/250.html?cmd=prntdoc
And I understand how the example in the release notes is illegal in that they are asking for instances of a joined class (i.e. b), and not instances of A who is the owner.
But, that's not the same thing I'm doing here. I'm asking for Asset to be joined with all of it's relationships, but only counting on the instances of Asset. So I'm asking for the equivalent of count(A) in the example so Asset is the owner. Why is that not valid?
I can think of several ways to fix this like dropping the joins, but what happens when I need a join to express something in the where clause? I'm just trying to count the maximum results that could occur from my query, but I'm trying to do it generically so I can write reusable pagination.
Thanks
Charlie