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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:30:52+00:00 2026-06-01T11:30:52+00:00

I have a tree-like object, managed by Hibernate. The object has a list of

  • 0

I have a tree-like object, managed by Hibernate. The object has a list of children and each child has its own custom_order within a parent:

<hibernate-mapping>
  <class name="MyClass" .../>
  <property .../>
  <property .../>
  <list name="children" cascade="save-update" inverse="false">
    <key column="parent_id"/>
    <index column="custom_order"/>
    <one-to-many class="MyClass"/>
  </list>
</hibernate-mapping>

The custom_order exists here in order to maintain the order of children within a parent but has no representation in the Java POJO and is managed directly by Hibernate. The only thing I have to do is to supply a list and custom_order will be auto-generated. So far so good.

What I want to achieve is the ability to use Criteria API and order by custom_order. At the moment I simply can not do anything like

criteria.addOrder(Order.asc("custom_order"));

because there is no such POJO property.

Question: is there a way to use Criteria API for this scenario without adding POJO getter/setter?

EDIT: I don’t mind adding relevant custom_order attribute to MyClass but I just don’t think this is possible in Hibernate.

  • 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-01T11:30:54+00:00Added an answer on June 1, 2026 at 11:30 am

    It is possible to map custom_order attribute to MyClass without adding getter or setter for this attribute . Just configure custom_order attribute to be access by field .

    Also , to prevent developers from changing the custom_order property using reflection , make custom_order to be read-only by setting insert and update to false:

    <property name="customerOrder" column="custom_order" access="field" insert="false" update="false"/>
    

    Currently , Order in Criteria API only can process mapped properties . If you don’t want to map custom_order attribute to MyClass, you can achieve your purpose if Order in Criteria API support sorting by native SQL. There are some requests for this support (HHH-1356 ,HHH-2381 , HHH-3315) but they are still unresolved now.

    Luckily , someone had already extended the Order class in order to support ordering by native SQL . So ,if you don’t map custom_order column for MyClass , you can simply use this extended Order class :

    addOrder(new NativeSQLOrder("custom_order" ,true))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree of objects, where each object has a std::vector of pointers
I am trying to have a javascript object tree behave like a php associative
I have an object tree that looks something like Ball / \ LegalBall IllegalBall
I have a binary tree in unordered list that looks like this: <ul> <li>1
I have a tree-like object structure that consists of two types of objects: object
I have an object-oriented parent-child tree in PHP that I want to clone. The
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have objects in a tree structure, I would like to aggregate status information
I have a tree structure in memory that I would like to render in
I am trying to have a tree display custom data that looks like this.

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.