Hibernate version: 3.1.3
Hibernate Annoations 3.1 beta9
I have properties defined on an enumerated type. Is it possible to use an enum in an HQL query? The enum in question is a lookup table and is references, via @Enumerated, by mapped entities.
Enumerated type definition...
Code:
public enum ComponentType
{
GLOBAL(1,"Global","Global"),
... other enum types ...
private long _id;
private String _name;
private String _description;
ComponentType(long id, String name, String desc)
{
_id = id;
_name = name;
_description = desc;
}
... getters/setters ...
}
I then have a mapped entity that references this enum
Code:
@Entity
@Table(name="Component")
@SequenceGenerator(name="ComponentSeq",sequenceName="COMPONENT_SEQ")
public class Component implements Serializable
{
private long _id;
private ComponentType _componentType;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ComponentSeq")
public long getId()
{
return _id;
}
public void setId(long id)
{
_id = id;
}
@Enumerated
@Column(name="componenttype_id",nullable=false)
public ComponentType getComponentType()
{
return _componentType;
}
public void setComponentType(ComponentType componentType)
{
_componentType = componentType;
}
}
Now I want to query for Components that have a particular ComponentType.name like so...
Code:
Query query = session.createQuery("from Component where componentType.name = :typeName");
query.setParameter("typeName", ComponentType.GLOBAL, Hibernate.STRING);
When I execute the query I get an exception saying "could not resolve property: name"
Is it possible to use an enum type this way or will I have to map the ComponentType class as a normal class and use static constants instead of an enum type?
thanks,
Brett