Hi, I'm sorry if this is a basic question but I've looked all over for the answer to this.
I'm trying to select lodgings (hotel, bed and breakfast, etc) based on features that a customer requests. I've modelled this as a Lodging class and a LodgingFeature class, both as entities in Hibernate with a many-to-many relationship between them.
This works fine until it comes time to selecting lodgings that match the customer's criteria. I've written the following query:
Code:
select l from Lodging l where elements(l.lodgingFeatures) in :features
I then set the features parameter as a java.util.List of LodgingFeature. This seems to work, the generated SQL looks something like this:
Code:
select lodging0_.id as id, ... from lodging lodging0_ where ((select lodgingf1_.lodging_feature_id from lodging_lodging_feature lodgingf1_ where lodging0_.id=lodgingf1_.lodging_id)in ? )
This SQL looks fine to me, my problem is that I'm using MySQL, which does not support subselects. Does anyone have any idea how I can avoid the subselect in this situation? Or will I have to use raw JDBC:
Code:
select lodging_id from lodging_lodging_feature where lodging_feature_id in (list of ids)
To query the junction table for the matching lodging IDs then use Hibernate to retrieve the objects (yuk).
Thanks in advance for any advice.