-->
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.  [ 2 posts ] 
Author Message
 Post subject: Shared interest query
PostPosted: Sat Apr 12, 2008 12:06 am 
Newbie

Joined: Fri Apr 11, 2008 11:45 pm
Posts: 7
Hi,

I'm trying to run an HQL query that should do the following :

I have a User. The User has a set of Interrest.


I want my query to find all the Users that share at least N Interests with the Person with id X.

Here is my person class :


Code:
public class User {

   private Long id;
        private Set<Interest> interests;

/**
    * @return the id
    */
   public Long getId() {
      return id;
   }

   /**
    * @param id
    *            the id to set
    */
   public void setId(Long id) {
      this.id = id;
   }

/**
    * @return the interests
    */
   public Set<Interest> getInterests() {
      return interests;
   }

   /**
    * @param interests the interests to set
    */
   public void setInterests(Set<Interest> interests) {
      this.interests = interests;
   }

}



Here is my Interest class :

Code:



import java.util.Set;

public class Interest {
   
   private Long id;
   private String name;


   /**
    * @return the id
    */
   public Long getId() {
      return id;
   }
   /**
    * @param id the id to set
    */
   public void setId(Long id) {
      this.id = id;
   }
   /**
    * @return the name
    */
   public String getName() {
      return name;
   }
   /**
    * @param name the name to set
    */
   public void setName(String name) {
      this.name = name;
   }
}




and here are the corresponding mappings

Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping>
   <class name="model.User" table="user">
      <id name="id" column="id">
          <generator class="native"/>
         <!--<generator class="sequence">
            <param name="sequence">address_id_seq</param>
         </generator>-->
      </id>

   
        <set name="interests">
          <key column="userid"/>
          <one-to-many class="model.Interest"/>
        </set>








Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping>
   <class name="model.Interest" table="interest">
      <id name="id" column="id">
          <generator class="native"/>
         <!--<generator class="sequence">
            <param name="sequence">address_id_seq</param>
         </generator>-->
      </id>
      
      
      <property name="name" column="name"/>
      

   </class>
</hibernate-mapping>






So a user can have many Interests.

I want to find all the users that have at least N interests in common with the User U.

I don't know if it's possible to do this with one simple HQL query or if should make multiple queries...

Any help appreciated

Thanks !


Top
 Profile  
 
 Post subject: bump
PostPosted: Sat Apr 12, 2008 8:51 pm 
Newbie

Joined: Fri Apr 11, 2008 11:45 pm
Posts: 7
can anyone help ?


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

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.