How should I refer to inner enums (defined within an entity) from a JPQL query using Hibernate?

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'

Answers


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.


select t from Thing t where t.state='AWESOME'

Need Your Help

Flask - Avoid putting full username and password in config

python shell flask debian

I am doing automatic deployments from GIT and I wanted to avoid putting my full username and password within the config.py like this:

AVPlayer streaming progress

iphone ios avplayer

I'm successfully using AVPlayer to stream audio from a server and what I want to do now is to show a custom UISlider who shows the progress of the buffering.