Solution to Hibernate error: Unknown column ‘******’ in ‘order clause’

Bug: A above exception thrown when using hibernate.

Reason: This error occurs usually because of a misplaced “order by” clause.
If in a many to many mapping, the serial order is defined in the cross reference table, the order-by attribute should be provided in the “collection” node as below –

<bag name="projects" ... table="users_projects" inverse="true" order-by="sl_num">
  		<key column="userId"/>
  		<many-to-many column="projectId" class="Project"/>

On other hand, if the collection is to be sorted by a column defined in the collection member, the order-by should be provided in the many-to-many or one-to-many node, as shown below.

<bag name="projects" ... table="users_projects" inverse="true">
  		<key column="userId"/>
  		<many-to-many column="projectId" class="Project"  order-by="name"/>

Solution: Move the order-by attribute to appropriate node depending on which table holds the sorted field.

Leave a Reply

Your email address will not be published. Required fields are marked *


* Copy This Password *

* Type Or Paste Password Here *

68,488 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>