I have some troubles in my app using sqlRestriction method:
This is my movie class:
public class Movie {
@Id
@Column(name = "pk")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "movie_seq")
@SequenceGenerator(name = "movie_seq", sequenceName = "movie_seq", allocationSize = 1, initialValue = 1)
public long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "name")
public String str_name = "";
...
}
When i do something like that (dummy test):
List<Movie> movies = session.createCriteria(Movie.class)
.add(Restrictions.sqlRestriction("1 in (1)"))
.list();
It Works perfectly.
My second test (changing the Restriction):
.add(Restrictions.sqlRestriction("Movie.id in (166,171)"))
And my third test
add(Restrictions.sqlRestriction("{Movie}.id in (166,171)"))
Both of them fails in the same way:
ERROR: Token SQL92 no soportado en la posición: 345
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
...
Caused by: java.sql.SQLException: Token SQL92 no soportado en la posición: 345
at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql.java:1275)
...
What am I doing wrong?
Edited
I tried :
.add(Restrictions.sqlRestriction("{alias}.id in (?, ?)", new Long[]{166L,171L}, new Type[]{Hibernate.Long, Hibernate.Long}) )
And i got this : "Long cannot be resolved or is not a field"
It seems "Hibernate.{AnyType}" is deprecated, see this link: Why Hibernate STRING can not be resolved?
i tried this instead:
.add(Restrictions.sqlRestriction("{alias}.id in (?, ?)", new Long[]{166L,171L}, new Type[]{LongType.INSTANCE, LongType.INSTANCE}) )
But I got this error:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "THIS_"."ID": invalid identifier