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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:17:08+00:00 2026-05-19T13:17:08+00:00

I’m aware that similar question have been asked here and here and it could

  • 0

I’m aware that similar question have been asked here and here and it could probably be a duplicate.

But the question has not been answered in both the places properly so reluctantly, I have to ask it again 🙁

The question is can you use Criteria API to join two tables when there is no mapping available between them.

E.g

class Order{ UserId , OrderId} 
 class User{UserId , UserName}

and I need to produce a query like,

select user.UserName , order.OrderId from Order order join User user on order.UserId = user.UserId

Please help if anyone is aware of this..and please do note that I need to do it using Criteria or QueryOver techniques

Thanks
/BB

  • 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-19T13:17:09+00:00Added an answer on May 19, 2026 at 1:17 pm

    Here is an idea on how it can be done but it is a bit ugly.

    Since the mapping does not state that the relationship between Order and User exists therefore it is pretty difficult to have NHibernate generate a join between these two tables.
    What you can do instead is do an inner select so your query as SQL would look like this:

    SELECT o.OrderId, o.WhateverOtherPropertyNameFromOrder
           (SELECT u.UserName, u.WhateverOtherPropertyNameFromUser
            FROM   User u
            WHERE  u.UserId = o.UserId)
    FROM   Order o
    

    This can be done like this on QueryOver:

    Order order = null;
    User user = null;
    
    QueryOver<User> query = QueryOver.Of<User>(() => user)
        .Select(Projections.ProjectionList()
                   .Add(Projections.Property<User>(x => x.UserName)))
                   .Add(Projections.Property<User>(x => x.WhateverOtherPropertyNameFromUser)))
        .Where(Restrictions.EqProperty("user.Id", "order.UserId"));
    
    var result = session.QueryOver<Order>(() => order)
        .Select(Projections.ProjectionList()
                .Add(Projections.Property<Order>(c => c.OrderId))
                .Add(Projections.Property<Order>(c => c.WhateverOtherPropertyNameFromOrder))
                .Add(Projections.SubQuery(query)))
        .List<object[]>();
    

    I have no idea if this is useful at all to you but it is a potential solution to your problem.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.