Hello Hibernate Community,
I am using JBoss EJB3 RC5 with PostgreSQL 8.1 and
I would like to make an EJB3 QL query that looks like this:
Code:
SELECT DISTINCT s FROM ServiceCase s LEFT JOIN s.products AS p WHERE ( s.id > 0) OR (p.productType.name LIKE '%xxxx%')
From my point of view this query should list all instances of class ServiceCase, because the expression
Code:
(s.id > 0)
is always
true. Instead it lists only the instances of class ServiceCase that are associated with at least one instance of class Product ... so i am missing all these service cases that have no products. This means, although the where-clause evaluates to
true, the select statement produces no results if there is no instance of class ServiceCase with at least one product in it's product list.
Do i use the LEFT JOIN the right way or is this possibly a bug?
A code listing of the classes i use:
Code:
@Entity
public class ServiceCase implements Serializable {
private int id;
private Set<Product> products = new HashSet<Product>();
@Id(generate=GeneratorType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
}
@Entity
public class Product implements Serializable {
private int id;
private ProductType productType;
@Id(generate=GeneratorType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne(optional=false)
public ProductType getProductType() {
return productType;
}
public void setProductType(ProductType product) {
this.productType = product;
}
}
@Entity
public class ProductType implements Serializable {
private String id;
private String name;
@Id
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Best regards,
Alexander