HSQLDB: Encountered a duplicated sql alias
<p>When I execute this query using a self-join from my java program </p>

<pre><code>Query query = session.createSQLQuery("SELECT DISTINCT * " +
            "FROM lerneinheit AS le1 JOIN lerneinheit AS le2  " +
            "ON le1.datum = le2.datum AND le1.pid = le2.pid " +
            " WHERE " +
            "  le1.datum BETWEEN  '2016-10-20' AND '2016-10-20'  AND " +
            "  le1.pid = 3 AND " +
            "  (le1.abgesagtrechtzeitig = false OR  le1.nichtabgesagt = true OR le1.erschienen=true) AND " +
            "  (le2.abgesagtrechtzeitig = false OR  le2.nichtabgesagt = true OR le2.erschienen=true) AND " +
            "  le1.lernid!= le2.lernid AND " +
            "  (le2.beginn+1 BETWEEN le1.beginn AND le1.ende OR le2.ende-1 BETWEEN le1.beginn AND le1.ende) " +
            " ORDER BY le1.beginn");
</code></pre>

<p>I get the following error: </p>

<pre><code>org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [LERNID] during auto-discovery of a native-sql query
</code></pre>

<p>Although it works fine if I do this from phpAdmin. Everything I found on that topic wasn't helpful at all. Anyone got any idea how to solve that?</p>