-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Querying parent/child entity for property style entities.
PostPosted: Fri Jun 04, 2010 3:52 pm 
Newbie

Joined: Fri Mar 21, 2008 11:35 am
Posts: 10
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.