Sorry about the 'Family' confusion - bad copy paste combo.
I am trying to retrieve all products with a product description under a locale.
Your query returns an array of product/productDetails objects. The productDetails objects are for the specified locale. However, if I do a product.getProductDetails on a product object that's returned, I get all productDetails objects regardless of locale. It seems like Hibernate is doing a second query when I fetch productDetails under product, but the second one does not pass in a locale, it just does a join on the id.
Here're the entity objects for Product and ProductDetails.
Code:
@Entity
@Table(name = "Products")
public class Product {
@Id
@Column(name = "ProductID")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@OneToMany(mappedBy = "product")
private List<ProductDetails> productDetails;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<ProductDetails> getProductDetails() {
return productDetails;
}
public void setProductDetails(List<ProductDetails> productDetails) {
this.productDetails = productDetails;
}
}
@Entity
@Table(name = "ProductDetails")
public class ProductDetails {
@Id
@Column(name = "ProductDetailID")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne
@JoinColumn(name = "ProductID")
private Product product;
@Column(name = "Locale")
private String locale;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
}