title: Hibernate exception 'could not resolve property' when doing a query with Criteria and Restrictions
body: <p>I have a OneToMany relation in hibernate defined like this:</p>
  
  <pre><code>@Entity
  @Table(name = "groups")
  public class Group extends BaseModel {// BaseModel defines id as @Id and @GeneratedValue
  
      @OneToMany
      @JoinColumn(name = "group_id")
      private List&lt;User&gt; users;
  
      // other fields, getters and setters omitted 
  }
  
  
  @Entity
  @Table(name = "users")
  public class User extends BaseModel {
  
      @ManyToOne
      @JoinColumn(name = "group_id")
      private Group group;
  
      // other fields, getters and setters omitted 
  }
  </code></pre>
  
  <p>Column <code>group_id</code> is in the users table.<br>
  Calling methods <code>Group.getUsers()</code> and <code>User.getGroup()</code> work fine. But I also need to do a query after the column <code>group_id</code>:</p>
  
  <pre><code>Criteria criteria = Activator.getDefault().getSQLSession().createCriteria(User.class);
  Criterion c = Restrictions.eq("group_id", 1); // an id of a group
  criteria.add(c);
  </code></pre>
  
  <p>The <code>Criterion</code> object is created in a method, and it can be for other <em>one-to-many</em> tables or can contain other columns, so I can't use method <code>getUsers()</code>.</p>
  
  <p>Unfortunatelly, the code above gives the following exception:</p>
  
  <pre><code>org.hibernate.QueryException: could not resolve property: group_id of: com.example.User
      at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
      at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
      at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1482)
      at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:62)
      and so on ...
  </code></pre>
  
  <p>What could be the problem?</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>After the change that <em>user759837</em> suggested (<code>Criterion c = Restrictions.eq("group", 1);</code>), when I call <code>criteria.list()</code>, I get this error message: <code>could not get a field value by reflection getter of com.example.Group.id</code></p>
  
  <pre><code>java.lang.IllegalArgumentException: Can not set java.lang.Long field com.example.BaseModel.id to java.lang.Long
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
      at sun.reflect.UnsafeObjectFieldAccessorImpl.get(Unknown Source)
      at java.lang.reflect.Field.get(Unknown Source)
      at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:227)
      at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3875)
      at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3583)
      at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
      at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:242)
      at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
      at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:130)
      ...
  </code></pre>
  
  <p>The BaseModel class is</p>
  
  <pre><code>@MappedSuperclass
  public abstract class BaseModel {
  
      @Id
      @GeneratedValue
      private Long id;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>I tried with <code>long id</code> too, but it's the same error.</p>
  
  <hr>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>After a lot of digging, it looks that the <code>Criterion</code> object should receive a group object as parameter, not an id: <code>Restrictions.eq("group", {A_GROUP_OBJECT});</code></p>
  
  <p>Could it be possible that I send there an id?</p>