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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:25:06+00:00 2026-05-29T07:25:06+00:00

Is it possible to do a join between 2 tables that don’t have foreign

  • 0

Is it possible to do a join between 2 tables that don’t have foreign keys?

Edit: Ok, I have been assured this is possible, but I’m not entirely sure how to do it yet.

Classes

public class Booking
{
    public virtual int Id { get; set; }
    public virtual Int32 bookingID { get; set; }
    public virtual Int32 bookingAdminID { get; set; 
}

public class BookingLocation
{
    public virtual int Id { get; set; }
    public virtual Int32 bookingID { get; set; }
    public virtual Int32 locationID { get; set; } 
}

Mappings

 public BookingMap()
 {
    Table("Bookings");

    Id(x => x.Id).Column("ID");
    Map(x => x.bookingID).Column("BookingID");
    Map(x => x.bookingAdminID).Column("BookingAdminID");
 }

public class BookingLocation
{
    public virtual int Id { get; set; }
    public virtual Int32 bookingID { get; set; }
    public virtual Int32 locationID { get; set; } 
 }

I need to do a simple inner join on bookingID of both table above. How would I do that?

I have tried:

var hql = "select b from Booking as b inner join BookingLocation as bl on b.bookingID =   bl.bookingID";
var bookings = session.CreateQuery(hql).List<object[]>(); 

but I get the error:

Semantic exception was unhandled by user code Path expected for join!

[select b from Booking as b inner join BookingLocation as bl on
b.bookingID = bl.bookingID]

I am taking this approach because I can’t easily build a relationship between these 2 tables in the mapping. Do you need to have a relationship in order to do a join?

  • 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-29T07:25:07+00:00Added an answer on May 29, 2026 at 7:25 am

    I was able to resolve this by adding relationships to my entities like so:

     public class Booking
     {
         public virtual int Id { get; set; }
         public virtual Int32 bookingID { get; set; }
         public virtual Int32 bookingAdminID { get; set; }
    
    
         public virtual IList<BookingLocation> BookingLocations { get; set; }
    
         public Booking()
         {
             BookingLocations = new List<BookingLocation>();
         }
     }
    
    public class BookingLocation
    {
        public virtual int Id { get; set; }
        public virtual Int32 bookingID { get; set; }
        public virtual Int32 locationID { get; set; } 
        public virtual Booking Booking { get; set; }
    }
    

    Even though they don’t have foreign keys, I was then able to do a join like this:

    var bookings = session.CreateCriteria<Booking>("p")
                                  .CreateCriteria("p.BookingLocations", JoinType.InnerJoin)
                                  .SetMaxResults(30) 
                                  .List<Booking>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to do a CROSS JOIN between 2 tables, followed by a
I have trouble grasping joins between more that two tables and it's syntax. I
I have a couple of tables that i join together when i execute the
Is it possible to join two classes without specified mapping between them (using Criteria
Possible Duplicate: What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN
Is it possible to do a cross table join in mysql spaning different tables?
I have two ( characteristic_list and measure_list ) tables that are related to each
The Query Optimizer is estimating that the results of a join will have only
I have this 3 tables in my DB: product (id, sku, type, price) ,
Feel like this should be something easy that I'm missing. I have a table

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.