Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1075323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:15:22+00:00 2026-05-16T21:15:22+00:00

EDIT> i am at a dead end… so i can continue looking for the

  • 0

EDIT> i am at a dead end… so i can continue looking for the main reason .. Please tell me how to make a simple criteria for many to many relationships which has more than one eq restrictions, for an example, how to get the person speaking eng & german in the example shown here…

My situation is like this i have two classes person and languages, with a n,m relationship.. And i am using a criteria to do the search – get all the persons which speak ex. English and German

@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;
    }

Criteria

    Criteria crit = session.createCriteria(Person.class);
    crit.setCacheable(true);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.property("languages"));
    c = enumMap.get(attr);
    if (c.isChanged()) {
       Criteria crit2 = crit.createCriteria("languages");
       Object[] o = (Object[]) c.getAnswer();
       Conjunction con = Restrictions.conjunction();
       for (int j = 0; j < o.length; j++) {
              Criterion tmp = Restrictions.eq("id", ((Languages)o[j]).getId());
              con.add(tmp);
       }
       crit2.add(con);

    }
    crit.setProjection(projList);
    retList = crit.list();

And the funny thing is, if i set it only for one language, i get the proper list of persons, but for more than one language i get none, i rechecked my base and set one person specifficaly to speak the 2 languages. But what tips mi more than anything is that the result from the projection in the Object[] on the place where the Set languages should be, there is NULL value……

please help
tnx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:15:23+00:00Added an answer on May 16, 2026 at 9:15 pm

    What you are doing in very old JDBC style (JDBC is what very old people used to access DB) would be something like this:

    SELECT * FROM PERSON WHERE LANGUAGE_ID = 1 AND LANGUAGE_ID = 2
    

    (just example, not exactly SQL)

    And, if you run this sql it will NEVER return a single line (Very sad…) because there is no line in the table with LANGUAGE_ID = 1 AND LANGUAGE_ID = 2.

    I don’t really know the best way to solve your problem (Hibernate is not my strongest skill), but in your case (if the languages number is not so big) i would make 2 (or 3, or a loop) of selections and join then using a simple Set in code. Not the best solution… And i will happy if someone show a better way

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.