Reputation: 52753
I have the following tables (simplified):
Product(Id, Name)
OrderItem(Id, ProductId)
...which map to the following classes:
Product {Id, Name}
OrderItem {Id, Product (many-to-one)}
I need the (N)Hibernate syntax to retrieve the Products that appear in Orders.
The SQL would be something like:
select *
from Product
where exists (
select *
from OrderItem
where OrderItem.ProductId = Product.Id)
How do I create the Criteria?
Upvotes: 3
Views: 1279
Reputation: 52753
It turned out to be easy...
var query = session.CreateQuery(
"select distinct oi.Product from OrderItem oi");
return query.List<Product>();
Upvotes: 3