3

This question answers the opposite relationship. I have been trying to come up with a Criteria Query for the following model:

@Entity
public class One {

    @Id
    private BigInteger supplierId;

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


    ...
}

@Entity
public class Many {

    @Id
    private BigInteger posId;

    @ManyToOne
    @JoinColumn(name = "column_name")
    One one;

    @Column(name = "description")
    String description;
}

I cannot change the model. I most keep it unidirectional in that way. I am trying to come up with the Criteria Builder code for the following situation: -I will be given the following attributes: nam, desc. I need to find all the One entities whose name attribute is equal to nam, and that have a related Many entity whose description attribute is equal to desc

snieguu
  • 2,073
  • 2
  • 20
  • 39
Jadiel de Armas
  • 8,405
  • 7
  • 46
  • 62

1 Answers1

-2
Criteria query = this.getSession().createCriteria(Many.class);
query = query.add(Restrictions.eq("one.name", nam));
query = query.add(Restrictions.eq("description", desc));
query.list();

This way doesn't work??