<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>OrderFactoryUtil and sorting by a composite primary key</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120681766" />
  <subtitle>OrderFactoryUtil and sorting by a composite primary key</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120681766</id>
  <updated>2026-04-04T12:40:40Z</updated>
  <dc:date>2026-04-04T12:40:40Z</dc:date>
  <entry>
    <title>OrderFactoryUtil and sorting by a composite primary key</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120681765" />
    <author>
      <name>Kevin Neibarger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120681765</id>
    <updated>2021-03-12T14:28:04Z</updated>
    <published>2021-03-12T14:28:04Z</published>
    <summary type="html">&lt;p&gt;I'm having issues doing an &amp;quot;addOrder&amp;quot; for a DynamicQuery
  for a field that is part of a composite key.&lt;/p&gt;
&lt;p&gt;My code looks like&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;DynamicQuery dynamicQuery =
    DynamicQueryFactoryUtil.&lt;i&gt;forClass&lt;/i&gt;(MyClass.class, this.getClassLoader());&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;dynamicQuery.addOrder(OrderFactoryUtil.&lt;i&gt;asc&lt;/i&gt;(&amp;quot;primaryKey.practice&amp;quot;));&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;My service.xml for that field is&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;&amp;lt;column name=&lt;i&gt;&amp;quot;practice&amp;quot;&lt;/i&gt;
    db-name=&lt;i&gt;&amp;quot;Practice&amp;quot;&lt;/i&gt;
    type=&lt;i&gt;&amp;quot;String&amp;quot;&lt;/i&gt; primary=&lt;i&gt;&amp;quot;true&amp;quot;&lt;/i&gt; /&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When executing the query, I get the following Exception&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;14:14:01,249 ERROR
    [http-bio-8080-exec-73][BasePersistenceImpl:244] Caught unexpected
    exception org.hibernate.QueryException&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;14:14:01,263 ERROR [http-bio-8080-exec-73][ClpSerializer:7376]
    java.lang.ClassNotFoundException: org.hibernate.QueryException&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;java.lang.ClassNotFoundException: org.hibernate.QueryException&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now, I've seen this before it just means that my field name above is
  incorrect from what is in my &lt;strong&gt;service.xml&lt;/strong&gt;, but I've
  used the prefix &lt;strong&gt;primaryKey&lt;/strong&gt; before with great results.
  Why can't I use this in the OrderFactoryUtil?? I am working with a
  Database View not a Table. I have another View and I'm able it query
  it with the &lt;strong&gt;primaryKey&lt;/strong&gt;
  &lt;strong&gt; &lt;/strong&gt;with no issues. What's wrong with &lt;strong&gt;OrderFactoryUtil??&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Kevin Neibarger</dc:creator>
    <dc:date>2021-03-12T14:28:04Z</dc:date>
  </entry>
</feed>
