-->
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.  [ 4 posts ] 
Author Message
 Post subject: Many to Many Criteria
PostPosted: Tue Sep 14, 2010 4:12 pm 
Newbie

Joined: Mon Sep 13, 2010 5:34 pm
Posts: 4
Code:

@Entity
public class Person implements Serializable {
    private int id;
           ...........
    private Set<Languages> languages = new HashSet<Languages>();
       ...............
    @ManyToMany
    @JoinTable(name = "link_person_languages")
    public Set<Languages> getLanguages() {
       return languages;
    }
}

@Entity
public class Languages implements Serializable {
    private int id;
    private String name;
    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    @Column(nullable = false, length = 40, unique = true)
    public String getName() {
        return name;
    }

Lets say i have Languages Eng Germ, People who speaks Eng, people who speaks German, and people who speaks Eng and German I want to get all of the people who speaks English and German using Criteria.
please help i am really desperate...


Top
 Profile  
 
 Post subject: Re: Many to Many Criteria
PostPosted: Tue Sep 14, 2010 4:37 pm 
Newbie

Joined: Wed Sep 01, 2010 1:18 pm
Posts: 3
I did something like this for a similar situation:

Code:
Criteria languageCriteria = session.createCriteria(Person.class);
languageCriteria.createAlias("languages","l");
criteria.add(Restrictions.in("l.name", new String[]{"English","German"}));
List<Person> matchingPeopleList = (List<Person>)languageCriteria.list();


HTH.


Top
 Profile  
 
 Post subject: Re: Many to Many Criteria
PostPosted: Tue Sep 14, 2010 5:04 pm 
Newbie

Joined: Mon Sep 13, 2010 5:34 pm
Posts: 4
gunners_newark wrote:
I did something like this for a similar situation:

Code:
Criteria languageCriteria = session.createCriteria(Person.class);
languageCriteria.createAlias("languages","l");
criteria.add(Restrictions.in("l.name", new String[]{"English","German"}));
List<Person> matchingPeopleList = (List<Person>)languageCriteria.list();


HTH.

not really :(

this here lists all the persons which speaks Eng, and all the persons which speaks German, but what i want is to list all the persons which speaks both languages.


Top
 Profile  
 
 Post subject: Re: Many to Many Criteria
PostPosted: Wed Sep 15, 2010 7:22 am 
Newbie

Joined: Mon Sep 13, 2010 5:34 pm
Posts: 4
PLEASE HELPPPPPPPPPPPPPPPP!!!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.