title: Hibernate predicates - Invalid path
body: <p>Let's have three entities: Event, MessageEvent and Message. MessageEvent is a subclass of Event (with correctly set DiscriminatorValue). MessageEvent has one additional property "message", which is of type Message. It is defined as below:</p>
  
  <pre><code>@ManyToOne(optional = false, cascade = CascadeType.REMOVE)
  @JoinColumn(name = "MESAGE_ID", nullable = false)
  private Message message;
  </code></pre>
  
  <p>Now, we're trying to set a predicate that will find all MessageEvent-s whose message's id is 2. We do it in the following way:</p>
  
  <pre><code>cb.equal(cb.treat(root, MessageEvent.class).join(MessageEvent_.message, JoinType.LEFT).get(Message_.id), 2)
  </code></pre>
  
  <p>The code compiles well, however, we get this error at runtime:</p>
  
  <pre><code>5:40:59,891 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (default task-2)  Invalid path: 'generatedAlias1.id':  Invalid path: 'generatedAlias1.id'
  at org.hibernate//org.hibernate.hql.internal.ast.util.LiteralProcessor.lookupConstant(LiteralProcessor.java:114)
  at org.hibernate//org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:214)
  at org.hibernate//org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:109)
  at org.hibernate//org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:104)
  at org.hibernate//org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1033)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4699)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4169)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2134)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2059)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2059)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:607)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
  at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)
  </code></pre>
  
  <p>Hibernate is apparently having a problem with the construction of the corresponding SQL query. Is the problem located in Hibernate itself or did we do anything wrong?</p>
  
  <p>A minimal demo is available at <a href="https://github.com/JurajMlich/hibernate-bug-demonstration" rel="nofollow noreferrer">https://github.com/JurajMlich/hibernate-bug-demonstration</a> . </p>
  
  <p>Tested on Java 8, Java 10 (openjdk), Wildfly 10, Wildfly 12. The same query is correctly handled when using eclipse link ORM.</p>