So I have a JPA 2 entity that is mapped like this:
Code:
public class UserInfo implements java.io.Serializable {
private long userId;
private Applications applications;
private Date createDate;
private String createProc;
private Set<UserQa> userQas = new HashSet<UserQa>(0);
....
@Id @GeneratedValue(generator="SEQ_USER_ID",strategy=GenerationType.SEQUENCE)
@Column(name = "USER_ID", unique = true, nullable = false, precision = 22, scale = 0)
public long getUserId() {
return this.userId;
}
....
@OneToMany(fetch = FetchType.EAGER, mappedBy = "userInfo", cascade=javax.persistence.CascadeType.ALL)
public Set<UserQa> getUserQas() {
return this.userQas;
}
....
}
Where UserQa is something like
Code:
public class UserQa implements java.io.Serializable {
private long rowId;
private UserInfo userInfo;
private String questionKey;
private String value;
private Date createDate;
}
It's essentially a key-value map, but in Set format. (I did try to make it an ElementCollection, however the mappings would never work right and generated extra tables)
The types of queries I'm trying to do would be something like
Code:
select u from UserInfo u fetch join u.userQas where u.userQas.questionKey = :someKey and u.userQas.value like :someValue
With the only problem is that I want to eagerly fetch all of the UserQa objects associated with this object, regardless of whether they are or not, but limit the results to the UserInfo where this key is like the given value.
I think I'm overly complicating it with how I'm thinking, but I'm a bit lost on how I would create this query.