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 8250953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:04:46+00:00 2026-06-08T00:04:46+00:00

i have the following query in SQL Server 2005: SELECT distinct(user.id_user), user.name, user.familyname from

  • 0

i have the following query in SQL Server 2005:

SELECT distinct(user.id_user), user.name, user.familyname from tbl_users users 
inner join tbl_notes notes on users.id_user = notes.id_user 
where notes.id_book = 1

I have all the necessary classes mapped and i need to write it using the hibernate API.
So far I have written the following code, but it’s returning null:

hibernateSession = HibernateUtil.getSessionFactory().openSession();
criteria = hibernateSession.createCriteria(TblUsers.class, "users")
        .createCriteria("users.id_user", "tblNotes")
        .add(Restrictions.eq("tblNotes.idBook", idBook));

criteria.setProjection(Projections.projectionList()
                .add(Projections.distinct(Projections.property("users.idUser")))
                .add(Projections.property("users.name"))
                .add(Projections.property("users.familyName")));

ret = criteria.list(); 
  • 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-06-08T00:04:48+00:00Added an answer on June 8, 2026 at 12:04 am
    Criteria c = session.createCriteria(User.class);
    Criteria nc = c.createCriteria("notes", "note");
    nc.add("bookId", 1);
    
    ProjectionList pl = Projections.projectionList();
    pl.add(Projections.distinct(Projections.property("userId")));
    pl.add(Projections.property("name"));
    pl.add(Projections.property("familyName"));
    c.setProjection(pl);
    
    List<Object[]> result = (List<Object[]>) c.list();
    

    Or something of this nature. The second “createCriteria” forces a join with the notes table, using your defined relationships. Since it appears that your notes table has a relationship with User (via the user_id column), i’ve assumed you have mapped it so that hibernate can figure out how to get from User to Note. In addition, the resulting Criteria object allows you to set conditions on the note being joined.

    Finally, we simply create a ProjectionList to enumerate the projections we want. In this case, we want 1 distinct column along with 2 other columns.

    What you’ll get back is a list of Object[].

    I have not tested this code, and since you didn’t post your classes, i’m not 100% sure everything is mapped in such a way that you can do a join like this.

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

Sidebar

Related Questions

I have the following SQL Server query: SELECT area FROM places WHERE REPLACE(area,'-',' ')
HI, Using SQL server 2005 I have the following query: SELECT contact_id ,YEAR(date_created) AS
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
Let's say I have the following SQL query SELECT id, name, title, description, time
Using SQL Server 2005 I have a table with the following columns id name
For instance, my query is like the following using SQL Server 2005: SELECT *
I am using MSSQL 2005 Server and I have the following SQL query. IF
In a SQL Server 2005 database I'm working on this query: select * from
I have the following SQL query: SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG

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.