<?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>CustomSQL - Column not found in ResultSet</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=112243755" />
  <subtitle>CustomSQL - Column not found in ResultSet</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=112243755</id>
  <updated>2026-04-06T22:07:37Z</updated>
  <dc:date>2026-04-06T22:07:37Z</dc:date>
  <entry>
    <title>RE: CustomSQL - Column not found in ResultSet</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112273395" />
    <author>
      <name>Pavle Milić</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112273395</id>
    <updated>2019-02-08T09:25:49Z</updated>
    <published>2019-02-08T09:25:49Z</published>
    <summary type="html">Thank you Amos, adding the entity class only for returning entity works!</summary>
    <dc:creator>Pavle Milić</dc:creator>
    <dc:date>2019-02-08T09:25:49Z</dc:date>
  </entry>
  <entry>
    <title>RE: CustomSQL - Column not found in ResultSet</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112255296" />
    <author>
      <name>Amos Fong</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112255296</id>
    <updated>2019-02-06T20:28:22Z</updated>
    <published>2019-02-06T20:28:22Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;If you're only retrieving menuItem objects, then I don't think you need to add the Menu entity to the query. Try removing this line:&lt;pre&gt;&lt;code&gt;q.addEntity("Menu", MenuImpl.class);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Then you should be able to use this again:&lt;pre&gt;&lt;code&gt;SELECT mi.*&lt;/code&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Amos Fong</dc:creator>
    <dc:date>2019-02-06T20:28:22Z</dc:date>
  </entry>
  <entry>
    <title>CustomSQL - Column not found in ResultSet</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112243754" />
    <author>
      <name>Pavle Milić</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112243754</id>
    <updated>2019-02-05T18:19:14Z</updated>
    <published>2019-02-05T18:19:14Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;I'm using CustomSQL to run the following query in Liferay v7.1:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;sql id="MenuItem.findItemsByPortalAndOrientation"&amp;gt;
   
      SELECT mi.*
      FROM MenuItem mi JOIN Menu m  
      ON m.id = mi.menu_id
      WHERE m.portal_id = ? AND m.orientation = ? AND m.active = true
      ORDER BY mi.createddate DESC
   
&amp;lt;/sql&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;I have mapped entity aliases to their implementation classes like this:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;
    @SuppressWarnings("unchecked")
	public List&amp;lt;menuitem&amp;gt; findByPortalAndOrientation(Long portalId, String orientation, int begin, int end) {
		Session session = null;
		try {
			session = openSession();
			String sql = _customSQL.get(getClass(), FIND_ITEMS_BY_PORTAL_AND_ORIENTATION);
			SQLQuery q = session.createSQLQuery(sql);
			q.setCacheable(false);
&amp;amp;nbsp;                        // alias mapping
			q.addEntity("Menu", MenuImpl.class);
			q.addEntity("MenuItem", MenuItemImpl.class);
			LoggerFactory.getLogger(getClass()).info("Query.." + q);
			QueryPos qPos = QueryPos.getInstance(q);
			qPos.add(portalId);
			qPos.add(orientation);
			LoggerFactory.getLogger(this.getClass()).info("" + QueryUtil.list(q, getDialect(), begin, end));
			return (List&amp;lt;menuitem&amp;gt;) QueryUtil.list(q, getDialect(), begin, end);
		} catch (Exception e) {
			try {
				throw new SystemException(e);
			} catch (SystemException se) {
				se.printStackTrace();
			}
		} finally {
			closeSession(session);
		}
		return null;
	}
&amp;lt;/menuitem&amp;gt;&amp;lt;/menuitem&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;This is what I get in the log:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;2019-02-05 17:36:12.060 INFO  [default task-26][MenuItemFinderImpl:45] Query..{names=null, _sqlQuery=SQLQueryImpl(  SELECT mi.* FROM MenuItem mi JOIN Menu m ON m.id = mi.menu_id WHERE m.portal_id = ? AND m.orientation = ? AND m.active = true ORDER BY mi.createddate DESC   ), _strictName=true}

2019-02-05 17:36:12.082 ERROR [default task-26][JDBCExceptionReporter:234] The column name orientation was not found in this ResultSet.&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;When I compare the parameter to any column other than "&lt;strong&gt;orientation"&lt;/strong&gt;&amp;nbsp;from the entity &lt;strong&gt;Menu&lt;/strong&gt; it works. Query also succeeds when I use change select clause:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;sql id="MenuItem.findItemsByCourtAndOrientation"&amp;gt;
    
        SELECT * // select all instead of mi.*
        FROM MenuItem mi JOIN Menu m  
        ON m.id = mi.menu_id
        WHERE m.portal_id = ? AND m.orientation = ? AND m.active = true
        ORDER BY mi.createddate DESC
    
&amp;lt;/sql&amp;gt;
&lt;/code&gt;&lt;/pre&gt;...but in that case the resultset doesn't map to objects correctly as I get the list of weird objects. I tried many other variations of the query but nothing would do.&lt;br&gt;&lt;br&gt;This is the mapping of this column in &lt;em&gt;service.xml:&lt;/em&gt;&lt;br&gt;(Btw I ran the service builder many times after this)&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;entity name="Menu" local-service="true" remote-service="false" table="menu" data-source="extDataSource" cache-enabled="false"&amp;gt;
    &amp;lt;column name="id" db-name="id" primary="true" type="long" /&amp;gt;
    &amp;lt;column name="orientation" db-name="orientation" type="String" /&amp;gt;
    ...
    ...
&amp;lt;/entity&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;What could be the cause of this error?&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Pavle Milić</dc:creator>
    <dc:date>2019-02-05T18:19:14Z</dc:date>
  </entry>
</feed>
