title: Hibernate Criteria setMaxResults with Oracle 11G giving org.hibernate.exception.SQLGrammarException: ORA-00918: column ambiguously defined
body: <p>We are using Hibernate 4.0 with JBoss 7 against an Oracle 11G database.  The java pojo class has these two properties (in addition to others).  Please note that the SalesPerson class has a SalesPersonId, a composite key that persists to the SalesOrder table.</p>
  
  <pre><code>public class SalesOrder extends OurBaseClass&lt;SalesOrder&gt;{
      private SalesPersonId salesPersonId;
      private SalesPerson salesPerson;
  
      @Embedded
      @AttributeOverride(name = "location", column = @Column(name = "sale_person_loc"))
      @XmlElement
      public SalesPersonId getSalesPersonId() {
         return salesPersonId;
      }
      public void setSalesPersonId(SalesPersonId salesPersonId) {
          this.salesPersonId = salesPersonId;
      }
      //The below object contains a SalesPersonId as composite primary key
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumns( {
      @JoinColumn(name = "sales_person_no",  insertable = false, updatable = false),
      @JoinColumn(name = "sales_person_loc",  insertable = false, updatable = false)
      } )
      @XmlElement
      public SalesPerson getSalesPerson() {
          return salesPerson;
      }
      public void setSalesPerson(SalesPerson salesPerson) {
          this.salesPerson = salesPerson;
      }
  }
  </code></pre>
  
  <p>The hibernate criteria code is as follows:</p>
  
  <pre><code>Session session = (Session) manager.getDelegate();
  Criteria criteria = session
      .createCriteria(SalesOrder.class,"so")
      .createAlias("salesPerson", "salesperson",JoinType.LEFT_OUTER_JOIN)
      .setMaxResults(100)
      .addOrder(Order.asc("id"));
  </code></pre>
  
  <p>The sql generated by hibernate is this:</p>
  
  <pre><code>select * from ( select this_.sales_person_no as sales_person4_641_2_,
              this_.sales_person_loc as sales_person5_641_2_, 
              this_.SALES_PERSON_NO as SALES_PERSON4_641_2_
              from SALES_ORDER this_, sales_person sales_person2_
              where this_.sales_person_no=sales_person2_.sales_person_no(+) and
              this_.sales_person_loc=sales_person2_.loc(+) 
  order by this_.order_no asc ) where rownum &lt;= ?
  </code></pre>
  
  <p>The error that is returning is due to the duplicate column names generated by hibernate.  Is there anything that can be done about this error?  I know if I remove SalesPersonId from the pojo, I don't get the error, however, I have been told that the class needs both the SalesPerson and the SalesPersonId.  I also know if I remove the setMaxResults I don't get the error, however, that is not an option.  Thank you for any help.</p>