Using Hibernate 3.1.2 & MSSQL 2000 I've got a simple one-to-many relationship mapped between an Employee object and a LeaveRequest object (one object per-table) and it's generating some SQL I would have not expected to see...since this is very typical relationship.
Employee mapping:
LeaveRequest mapping:
SQL output (fields abbreviated w/ '*' for readability):
I would have expected to see a single "select x,y,z from requests where employee_id = ?" type of query...not a whole slew of them
testing against a sub-query. Everything *works* but obviously, I'd like to see less queries being generated.
I would believe it's the n+1 selects problem but this is test data and only one of the employee records as leave request records...and that employee only has 3 records...so I'm probably just not seeing a goof in my mapping files somewhere.
I've tried tweaking it by removing the inverse relationship...but the problem returns. I can't use a join w/o making the employee show up 3 times in the master list...so I'd rather use select.
I'm using the official MSSQL 2000
JDBC driver...and this type of mapping is working elsewhere in my app w/o this type of strangeness.
Any ideas?
Thanks!