JPA: Conditionally get some child objects

I am trying to create a NamedQuery object for a parent that retrieves all available parent objects from the database and conditionally retrieves some of the child objects in a single query. For instance. the query should retrieve all the parent objects and retrieve children that have year = 2012 for each parent. Other child objects should not be retrieved. I tried to play arround with LEFT JOIN FETCH, but the result was that some of the parent objects were also excluded. But then again, I'm new to the FETCH statement.

Is there a way to achieve the above task? Any help is much appreciated. The corresponding code for my parent is given below:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "xxx/xxx/xxx/xxx", name = "Parent")
@XmlRootElement(namespace = "xxx/xxx/xxx/xxx")
public class Parent implements Serializable {
private static final long serialVersionUID = 1L;

/**
 */
.....................
/**
 */

@Column(name = "status")
@Basic(fetch = FetchType.EAGER)
@XmlElement
String status;
/**
 */
/**
 */
@OneToMany(mappedBy = "parent", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
@XmlElement(name = "", namespace = "")
java.util.Set<xxx.xxx.xxx.Child> children;
+3
source
1

, , @Where - , , children

@Where(clause="year=2012")

. : Entity- Bean @OneToMany

+2

All Articles