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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:09:54+00:00 2026-05-17T01:09:54+00:00

I have 2 entities Role & Translation. Role -> Role_ID, Code Translation -> Code,

  • 0

I have 2 entities Role & Translation.
Role -> Role_ID, Code
Translation -> Code, Language, Name

The idea is to say for a certain role, that it has English name, French name and so on.
For example:
A Role(1, ‘Rol_001’) can have the relations: Translation(‘Rol_001’, ‘English’, ”) & Translation(‘Rol_001’, ‘French’, ”).

I would like to express the following SQL query in HQL:


select r.Role_ID, t.Name
from Role r left outer join Translation t 
   on r.Code = t.Code and t.Language = @lang;

In my mapping files I don’t have any relation between the 2 entities but the following HQL query works as if it is inner join


IQuery query = session.CreateQuery("select new Lookup(r.Role, t.Name) from Role r, Translation t where r.Code = r.Code and t.Language = :language");

If I change the HQL to left outer join, I get the Path expected for join exception.

Can you help me with the following:
1- Do I need to change my mapping files?
2- If I can keep the mapping files as is, how write such a query in HQL?
3- How does HQL really works? Why such a simple outer join query is not working? I must be missing something here!

Edit:
Now I am using the following code based on the suggetion to use CreateSQL:


ISQLQuery query = session.CreateSQLQuery("select m.MedicineTypeID, t.Name, m.IsDeleted from MedicineType m left outer join Translation t on m.Code = t.Code and t.Language = :language");
query.SetString("language", language);
IList rawLookup = query.List();

IList medicineTypesLookup = new List(rawLookup.Count);
foreach (object[] lookup in rawLookup)
{
    medicineTypesLookup.Add(new Lookup((int)lookup[0], (string)lookup[1], (bool)lookup[2]));
}
return medicineTypesLookup;

This is working however I want to use query.List() to get the result directly instead of converting it myself.
I tried to use query.AddEntity(typeof(Lookup)); but I get the exception NHibernate.MappingException: No persister for: DAL.Domain.Lookup.
The Lookup is just a POCO and doesn’t map to any database table. Its mapping file is simply <import class="Lookup" />

  • 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-17T01:09:55+00:00Added an answer on May 17, 2026 at 1:09 am

    Finally I found the answer:

    ISession session = NHibernateHelper.Session;
    ISQLQuery query = session.CreateSQLQuery("select m.MedicineTypeID as ID, t.Name, m.IsDeleted from MedicineType m left outer join Translation t on m.Code = t.Code and t.Language = :language");
    query.setString("language", language);
    IList lookup = query.SetResultTransformer(Transformers.AliasToBean()).List();
    return lookup;
    

    And the lookup is a POCO class with a parameterless constructor and 3 properties ID, Name and IsDeleted.

    I would like to thank Kelly and Diego Mijelshon for their hints. Although they don’t provide the full answer the but using Session.CreateSqlQuery() was a very useful hint.

    So the complete solution is Session.CreateSQLQuery and query.SetResultTransformer

    Note: Transformers.AliasToBean() is so java.

    Edit: http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/impl/SQLQueryImpl.html for correct method of setString()

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

Sidebar

Related Questions

i have 2 entities: User and Role i have one class Userrole that will
In my Azure role I have a lot of entities that have to be
I have in symfony created 2 entities: User and Role in many-to-many relationship. That
I have two entities, a User and Role with a one-to-many relationship from user
I have entities similar to: ProductLine: id, name ProductLineContents: content_id, product_line_id Content: id, text,
I'm working on a web application. I have entities that are supposed to be
I am using Entity Framework and DevExpress 10.5 XtraGrid. Imagine that we have entities
I have two entities Visita and Cliente that implements respectively two interfaces IVisita and
I have 2 entities User and Role Role.hbm.xml : <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping
I have two entities. User and Role. I am using Devise and CanCan. They

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.