title: Hibernate Subqueries.exists
body: <p>I am having a problem with a Subqueries.exists criteria.</p>
  
  <p>I have the following:</p>
  
  <pre><code>DetachedCriteria criteria = DetachedCriteria.forClass(Expense.class, "mainExpense")
          .add(Restrictions.eq("group", group))
          .addOrder(Order.desc("created"));
  
  if (all) {
      criteria.add(
              Restrictions.or(
                      Restrictions.eq("status", ExpenseStatus.PENDING),
                      Restrictions.eq("status", ExpenseStatus.COMPLETE)
              ));
  } else {
      criteria.add(Restrictions.eq("status", ExpenseStatus.PENDING));
  }
  
  if (user != null) {
      DetachedCriteria userSubCriteria = DetachedCriteria.forClass(UserExpense.class, "userExpense")
              .add(Restrictions.eq("userExpense.primaryKey.user", user))
              .add(Restrictions.eq("userExpense.primaryKey.expense", "mainExpense"))
              .setProjection(Projections.property("userExpense.primaryKey"));
      criteria.add(Subqueries.exists(userSubCriteria));
  }
  
  return getHibernateTemplate().findByCriteria(criteria);
  </code></pre>
  
  <p>If I pass a null user (not using the Subqueries.exists) it works okay and returns me the valid  expense items. If I give a user if given me the following:</p>
  
  <p>org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of Expense.id; nested exception is org.hibernate.PropertyAccessException: could not get a field value by reflection getter of Expense.id</p>
  
  <p>and lower in the logs:</p>
  
  <p>Can not set java.lang.Integer field Expense.id to java.lang.String</p>
  
  <p>Does anyone have any idea of what I am doing wrong?</p>