Reputation: 2416
I have an entity class as follows:
package stuff;
@Entity
class Thing {
@Id
@GeneratedValue
private Long id;
@Basic
@Enumerated
private State state;
public enum State {
AWESOME,
LAME
}
}
How can I select all Things with state AWESOME using JPQL and Hibernate?
select t from Thing t where t.state=stuff.Thing.State.AWESOME
...gives the error...
org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'stuff.Thing.State.AWESOME'
Upvotes: 18
Views: 4001
Reputation: 2416
Use the following idiom:
select t from Thing t where t.state=stuff.Thing$State.AWESOME
Type$InnerType
is Java's naming convention for inner types.
When you try to use dot notation, Hibernate assumes that you're trying to access nested properties, which (properly) fails in this case.
Upvotes: 25