title: org.hibernate.exception.SQLGrammarException: could not prepare statement; nested exception is javax.persistence.PersistenceException
body: <p>I have 3 entity classes </p>
  
  <p>Ooline:</p>
  
  <pre><code>@Entity
  @IdClass(OolineId.class)
  @NamedQuery(name="Ooline.findAll", query="SELECT o FROM Ooline o")
  public class Ooline implements Serializable 
  {
      private static final long serialVersionUID = 1L;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumns({
          @JoinColumn(name="mitmas_mmcono" , referencedColumnName="mmcono"),
          @JoinColumn(name="mitmas_mmitno" , referencedColumnName="mmitno")
      })
      private Mitmas mitmas ;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumns({
          @JoinColumn(name="mitfac_m9cono", referencedColumnName="m9cono"),
          @JoinColumn(name="mitfac_m9itno", referencedColumnName="m9itno"),
          @JoinColumn(name="mitfac_m9faci", referencedColumnName="m9faci")
      })
      private Mitfac mitfac ;
  
      @Id
      private String obitno;
      @Id
      private BigDecimal obcono;
      @Id
      private String obfaci;
  
      private BigDecimal obabno;
  
      //getter and setters
  
  }
  </code></pre>
  
  <p>Mitfac:</p>
  
  <pre><code>@Entity
  @IdClass(MitfacId.class)
  @NamedQuery(name="Mitfac.findAll", query="SELECT m FROM Mitfac m")
  public class Mitfac implements Serializable 
  {
      private static final long serialVersionUID = 1L;
  
      @OneToMany(mappedBy="mitfac",fetch=FetchType.LAZY)
      private List&lt;Ooline&gt; oolineItem; 
  
      @Id
      private String m9itno;
      @Id
      private String m9faci;
      @Id
      private BigDecimal m9cono;
  
      private String m9acrf;
  
      private BigDecimal m9appr;
  
      //getter and setter
  
  }
  </code></pre>
  
  <p>Mitmas:</p>
  
  <pre><code>@Entity
  @IdClass(MitmasId.class)
  @NamedQuery(name="Mitmas.findAll", query="SELECT m FROM Mitmas m")
  public class Mitmas implements Serializable 
  {
      private static final long serialVersionUID = 1L;
  
      @OneToMany(mappedBy="mitmas",fetch=FetchType.LAZY)
      private List&lt;Ooline&gt; ooline; 
  
      @Id
      private String mmitno;
      @Id
      private BigDecimal mmcono;
  
      private BigDecimal mmaad0;
  
      private BigDecimal mmaad1;
  
      private String mmaccg;
  
      //getter and setter methods
  }
  </code></pre>
  
  <p>And following is my Repository file:</p>
  
  <pre><code>public interface OolineRepository extends JpaRepository&lt;Ooline, String&gt; 
  {
      public static final String ORDER_LINE_QUERY = 
              "select x.obcono,x.oborno,x.obponr, x.obposx, x.obfaci, x.obitno, x.obitds, x.oborqt, "
              + "x.oborqa, x.obwhlo, x.obadid, x.obpopn, x.obrout, x.obmodl, x.oborst,"
              + " x.obnepr, x.obdwdz, x.obcodz, x.obpldt, x.obplhm,"
              + " x.obprrf, x.obspun, x.obrgdt, x.obrgtm, x.obwhsl from Ooline x "
              + "left join x.mitmas y  left join x.mitfac z "
              + "where x.obcono = :cono and x.oborno = :orno";
  
      @Query(ORDER_LINE_QUERY)
      public List&lt;Ooline&gt; getOolineLines(@Param("cono") BigDecimal cono, @Param("orno") String orno);
  }
  </code></pre>
  
  <p>And the following persistense.xml</p>
  
  <pre><code>&lt;persistence-unit name="tables"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
  
          &lt;class&gt;xxx.Mitmas&lt;/class&gt;
          &lt;class&gt;xxx.Ooline&lt;/class&gt;
          &lt;class&gt;xxx.Mitfac&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" /&gt;
  
              &lt;!-- These options seem intended to be developers tools and not to facilitate 
                  any production level databases --&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="none" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.connection.charSet" value="UTF-8" /&gt;
              &lt;property name="hibernate.connection.driver_class" value="com.ibm.as400.access.AS400JDBCDriver" /&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:as400://host/schema" /&gt;
              &lt;property name="hibernate.connection.username" value="username" /&gt;
              &lt;property name="hibernate.connection.password" value="password" /&gt;
  
          &lt;/properties&gt; 
      &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>I am supposed to execute following query in SQL</p>
  
  <pre><code>"select x.oborno,x.obponr, x.obposx, x.obfaci, x.obitno, x.obitds, x.oborqt, x.oborqa,
  x.obwhlo, x.obadid, x.obpopn, x.obrout, x.obmodl,x.oborst, x.obnepr, x.obdwdz, x.obcodz,
  x.obpldt, x.obplhm,x.obprrf, x.obspun, x.obrgdt, x.obrgtm, x.obwhsl from Ooline x join
  m3fdbdem.mitmas on mmcono = obcono and mmitno = obitno left join  m3fdbdem.mitfac on
  m9cono = obcono and m9faci = obfaci and m9itno = obitno where obcono =1 and oborno = 'asasa'";
  </code></pre>
  
  <p>Can anyone verify if have constructed and mapped entity correctly</p>