Hibernate - Adding "distinct" in hql query

Posted on 2007-10-10
Last Modified: 2013-11-24

this is my query :

String query =
      "from MyBank b where "
            + "b.institution LIKE UPPER('"
            + startsWith + "%')";

I want to add a distinct on the institution field.
Thank you for any help.
Question by:matthew016
    LVL 23

    Assisted Solution

    Use Criteria, Projections
    Look at this question (Hibernate does not return distinct results for a
    query with outer join fetching enabled for a collection (even if I use the
    distinct keyword)?) here

    List result = session.createQuery("select o from Order o left join fetch

    // Yes, really!

    LVL 13

    Accepted Solution

    You can not put a distinct in the clause.

    You can select distinct rows though:

    select distinct b.institution from MyBank b where b.institution LIKE UPPER(:startsWith)

    This gives all institutions attached to a MyBank matching the startsWith.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Title # Comments Views Activity
    scoresIncreasing challenge 10 48
    hasOne  challenge 59 64
    advance java 4 36
    bunnyEars challenge 6 45
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now