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

  • Home
  • SEARCH
  • 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 7845493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:14:20+00:00 2026-06-02T17:14:20+00:00

Im new to java and hibernate. ExpenseType.java public class ExpenseType extends BaseDomain { private

  • 0

Im new to java and hibernate.

ExpenseType.java

public class ExpenseType extends BaseDomain {
  private int companyId;
  private String name;
  private String description;
  private Company company;

  // Getters and Setters
}

Company.java

public class Company extends BaseDomain {
  private String name;
  private String address;
  private String contactNumber;
  private String emailAddress;

  // Getters and Setters
}

I have 2 ojects ExpenseType and Company. They have a many-to-one relationship. The
mapping is in this file expenseType.hbm.xml.

expenseType.hbm.xml

<hibernate-mapping>
   <class name="bp.ar.domain.hibernate.ExpenseType" table="EXPENSE_TYPE">   
      .
      .
      <property name="companyId">
        <column name="COMPANY_ID"/>
      </property>

      <many-to-one name="company" class="bp.ar.domain.hibernate.Company" fetch="select" insert="false" update="false" lazy="false">
        <column name="COMPANY_ID" not-null="true" />
      </many-to-one>
   </class>
</hibernate-mapping>

I have COMPANY_ID foreign key in my ExpenseType table.

In my implementation in the file ExpenseTypeDaoImpl.java I do something like

@Override
public Collection<ExpenseType> getAll(int companyId, Collection<Company> companies,
     ExpenseTypeField orderBy) {
  DetachedCriteria dc = getDetachedCriteria();
  dc.addOrder(Order.asc("company"));
  dc.addOrder(Order.asc(orderBy.name()));
  return getAll(dc);
}

What I really want to happen is that the result for ExpenseType will be ordered based on the company name. What happens with code above is that it orders the ExpenseType based on tbe COMPANY_ID. I tried to use dc.addOrder(Order.asc("company.name")); but I get an error.

I have this error:

org.hibernate.QueryException: could not resolve property: company.name of: bp.ar.domain.hibernate.ExpenseType

Please help. Thanks in advance.

  • 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-02T17:14:21+00:00Added an answer on June 2, 2026 at 5:14 pm

    You need to create an alias to the relation before you can sort on its properties. This is analogous to a SQL JOIN.

    DetachedCriteria dc = getDetachedCriteria();
    dc.createAlias("company", "company");
    dc.addOrder(Order.asc("company.name"));
    return getAll(dc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Customer_
I am new to the Java / Hibernate / Seam way of development but
I am new to Java and Hibernate and I am trying to map the
I am new to Java and Hibernate. I've got problem with composite key. I
i'm fairly new to Java and Hibernate. At work we are developing a medium
I am new to Hibernate, reading this book Java persistence with Hibernate and I
I am trying to create a new Java EE project using hibernate and JPA
I'm new to using Hibernate with Java. I'm getting the following exception. The stuff
We are starting a new Java EE project and am looking for suggestions regarding

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.