0

I need to have query like this:

select * from TABLE where Source_KEY in (1,2);

My Hibernate class is like this:

@Entity
@Table(name = "TABLE", schema = "SCH")
public class Table {
    private Long key;
    private Long id;
    private Source src;
}

Source is another entity class,
@Entity
@Table(name = "SOURCE", schema = "SCH")
public class Source{
private Long Source_KEY;
}

Now i have written a criteria but it seems to have an issue. Please can anyone advice on this.

private static final List<String> STAY_SOURCE_KEY = asList(1,2);

criteria.add(Restrictions.in("Source_KEY", STAY_SOURCE_KEY));

This should be a list of Source class but how to to that in criteria. It has to form query like

select * from TABLE where Source_KEY in (1,2);
Pavel Smirnov
  • 4,611
  • 3
  • 18
  • 28
Rahul
  • 95
  • 1
  • 3
  • 14
  • Possible duplicate of [Hibernate Criteria Join with 3 Tables](https://stackoverflow.com/questions/8726396/hibernate-criteria-join-with-3-tables) – Peter Šály Mar 23 '19 at 22:30

1 Answers1

1

You need to join table. Use

criteria.createAlias("src","s");
criteria.add(Restrictions.in("s.Source_KEY", STAY_SOURCE_KEY));
Peter Šály
  • 2,848
  • 2
  • 12
  • 26