I am trying to query 2 tables using criteria. Below is the method:

```
   public UserEntity getUserOverView(long userId, String receiptMonth) {

  Session session = HibernateUtil.getSessionFactory().openSession();
   UserEntity user = new UserEntity();

  try {
     session.beginTransaction();

          Criteria criteria = session.createCriteria(UserEntity.class, "user")
           .createAlias("user.receiptEntitySet", "receipt")
           .add(Restrictions.eq("receipt.dateCreated", receiptMonth))
           .add(Restrictions.eq("user.userId", userId));

     user = (UserEntity) criteria.uniqueResult();

  } catch (Exception ex) {

     System.out.print(ex.getMessage());
  } finally {

     session.getTransaction().commit();
     session.close();

  }

  return user;

```

}

The above is successfully respecting the userId, however, I want to filter on the 'receiptMonth' in the other table. It seems to be ignoring the 'receiptMonth' restriction completely.

UserEntity:

```
    package za.co.skizzel.infrastructure.entities;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name="user")
public class UserEntity {

  @Id
  @GeneratedValue
  @Column(name="userId", unique = true, nullable = false, updatable = false )
  private Long userId;

  @Column(name="email")
  private String email;

  @Column(name="password")
  private String password;

  @Column(name="name")
  private String name;

  @OneToMany(fetch = FetchType.EAGER, mappedBy = "userEntity" , cascade = { CascadeType.ALL } )
  private Set<ReceiptEntity> receiptEntitySet;

   @OneToMany(fetch = FetchType.EAGER, mappedBy = "userEntity" , cascade = { CascadeType.ALL } )
   private Set<CategoryEntity> categoryEntitySet;

   public Set<CategoryEntity> getCategoryEntitySet() {
      return categoryEntitySet;
   }

   public void setCategoryEntitySet(Set<CategoryEntity> categoryEntitySet) {
      this.categoryEntitySet = categoryEntitySet;
   }

   public Long getUserId() {
      return userId;
   }

   public void setUserId(Long userId) {
      this.userId = userId;
   }

   public String getEmail() {
      return email;
   }

   public void setEmail(String email) {
      this.email = email;
   }

   public String getPassword() {
      return password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public Set<ReceiptEntity> getReceiptEntitySet() {
      return receiptEntitySet;
   }

   public void setReceiptEntitySet(Set<ReceiptEntity> receiptEntitySet) {
      this.receiptEntitySet = receiptEntitySet;
   }

   public UserEntity(){};

   public UserEntity(long userId){
      this.userId = userId;
   };

}

```

ReceiptEntity:

```
    package za.co.skizzel.infrastructure.entities;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name="receipt")
public class ReceiptEntity {

  @Id
  @GeneratedValue
  @Column(name="ReceiptId", unique = true, nullable = false, updatable = false )
  private Long receiptId;

  @Column(name="alias")
  private String alias;

   @Column(name="categoryId")
   private long categoryId;

  @Column(name="DateCreated")
  private String dateCreated;

  @ManyToOne
  @JoinColumn(name="userId", nullable=false, insertable = false, updatable = false)
  private UserEntity userEntity;

   @OneToMany(fetch = FetchType.EAGER, mappedBy = "receiptEntity" , cascade = { CascadeType.ALL } )
   private Set<ImageEntity> imageEntitySet;

   private long userId;

   public long getUserId() {
      return userId;
   }

   public void setUserId(long userId) {
      this.userId = userId;
   }

   public long getCategoryId() {
      return categoryId;
   }

   public void setCategoryId(long categoryId) {
      this.categoryId = categoryId;
   }

   public Long getReceiptId() {
    return receiptId;
  }

  public void setReceiptId(Long receiptId) {
    this.receiptId = receiptId;
  }

  public String getAlias() {
    return alias;
  }

  public void setAlias(String alias) {
    this.alias = alias;
  }

  public String getDateCreated() {
    return dateCreated;
  }

  public void setDateCreated(String dateCreated) {
    this.dateCreated = dateCreated;
  }

  public UserEntity getUserEntity() {
    return userEntity;
  }

  public void setUserEntity(UserEntity userEntity) {
    this.userEntity = userEntity;
  }

   public ReceiptEntity() {};

}

```

Not sure what I am doing wrong? Any guidance would be appreciated?

Thanks
Luke

EDIT

I am expecting something like:

```
select * from user, receipt where user.userId = '8' and receipt.dateCreated = 'January 2014'

```