title: could not resolve property: userId.username
body: <p>I have following entity classes:</p>
  
  <pre><code>@MappedSuperclass
  public class AbstractEntity implements Serializable, Comparable&lt;AbstractEntity&gt; {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "id")
      protected Integer id;
  
      @Override
      public int compareTo(AbstractEntity o) {
          return this.toString().compareTo(o.toString());
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
  }
  
  @Entity
  @Table(name = "ticket")
  @NamedQueries({
      @NamedQuery(name = "Ticket.findAll", query = "SELECT t FROM Ticket t")})
  public class Ticket extends AbstractEntity {
  
      @Column(name = "title")
      private String title;
      @Column(name = "description")
      private String description;
  
      @Enumerated(EnumType.STRING)
      @Column(name = "status")
      private TicketStatus status;
  
      @Enumerated(EnumType.STRING)
      @Column(name = "priority")
      private TicketPriority priority;
  
      @Column(name = "categories")
      private String categories;
      @Column(name = "views")
      private Integer views;
      @Column(name = "date_time_created")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dateTimeCreated;
  
      @Column(name = "date_time_modified")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dateTimeModified;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "ticketId")
      private List&lt;TicketFollower&gt; ticketFollowerList;
  
      @JoinColumn(name = "project_id", referencedColumnName = "id")
      @ManyToOne(optional = false)
      private Project projectId;
  
      @JoinColumn(name = "ticket_attachment_id", referencedColumnName = "id")
      @ManyToOne
      private TicketAttachment ticketAttachmentId;
  
      @JoinColumn(name = "user_id", referencedColumnName = "id")
      @ManyToOne(optional = false)
      private User userId;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "ticketId")
      private List&lt;TicketComment&gt; ticketCommentList;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "ticketId")
      private List&lt;TicketAttachment&gt; ticketAttachmentList;
  
      @Inject
      public Ticket() {
      }
  
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
      public String getDescription() {
          return description;
      }
  
      ...
  
      @Override
      public String toString() {
          return getTitle();
      }
  
  }
  
  @Entity
  @Table(name = "user")
  @NamedQueries({
      @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")})
  public class User extends AbstractEntity {
  
      @Enumerated(EnumType.STRING)
      @Column(name = "role")
      private Role role;
      @Column(name = "username")
      private String username;
      @Column(name = "password")
      private String password;
      @Column(name = "first_name")
      private String firstName;
      @Column(name = "last_name")
      private String lastName;
      @Column(name = "email")
      private String email;
      @Column(name = "avatar_path")
      private String avatarPath;
      @Column(name = "date_time_registered")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dateTimeRegistered;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
      private List&lt;TicketFollower&gt; ticketFollowerList;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
      private List&lt;Ticket&gt; ticketList;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
      private List&lt;TicketComment&gt; ticketCommentList;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
      private List&lt;ProjectFollower&gt; projectFollowerList;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
      private List&lt;TicketAttachment&gt; ticketAttachmentList;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
      private List&lt;Project&gt; projectList;
  
      @Inject
      public User() {}
  
      public Role getRole() {
          return role;
      }
  
      public void setRole(Role role) {
          this.role = role;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  </code></pre>
  
  <p>I get this exception from creating a hibernate <code>Criteria</code>. In my <code>TicketDao</code> class I have a method which search ticket by username, and when I invoke code below </p>
  
  <pre><code>Criteria criteria = session.createCriteria(Ticket.class);
  criteria.add(Restrictions.eq("userId.username", username));
  </code></pre>
  
  <p>it throws exception:</p>
  
  <pre><code>could not resolve property: userId.username of: com.entities.Ticket
  </code></pre>
  
  <p>However, when I write criteria like:</p>
  
  <pre><code>criteria.add(Restrictions.eq("userId.id", userId));
  </code></pre>
  
  <p>it does not show any exception and returns me result. Any idea why my syntax for <code>criteria.add(Restrictions.eq("userId.username", username));</code> and other properties like firstname, last name is wrong ?</p>