Hi,
I have an entity which can have a collection of enums. My mapping is like this:
Code:
@Entity
@Table(name="PARENT")
public class Parent {
public enum MyEnum{
ENUM_A,
ENUM_B,
ENUM_C,
ENUM_D;
}
private long parentId;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "PARENT_ID", unique = true, nullable = false)
public long getParentd() {
return this.parentId;
}
public void setParentId(long parentId) {
this.parentId = parentId;
}
private Set<MyEnum> myEnums = EnumSet.noneOf(MyEnum.class);
@CollectionOfElements(targetElement=MyEnum.class)
@JoinTable
(name="PARENT_MY_ENUM",
joinColumns=@JoinColumn(name="PARENT_ID"))
@Enumerated(EnumType.STRING)
@Column (name="MY_ENUM", nullable=false)
public Set<MyEnum> getMyEnums(){
return myEnums;
}
public void setMyEnums(Set<MyEnum> myEnums){
this.myEnums = myEnums;
}
}
This seems to work fine but when I want to use the collection in a HQL query things go wrong.
This is a simple HQL query:
Code:
select pa.parentId from Parent where pa.myEnums IN ('ENUM_A','ENUM_B')
This query is translated to MySQL as this:
Code:
select parent0_.PARENT_ID as PARENT1_0_, from PARENT parent0_, PARENT_MY_ENUM myenum1_ where parent0_.PARENT_ID=myenum1_.PARENT_ID and (. in ('ENUM_A' , 'ENUM_B'))
MySQL now complains about the '.'
What is going wrong here? Is my mapping wrong, the query or is this a bug in Hibernate?
I am using Hibernate 3.3
This is from the config:
Code:
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="hibernate.query.jpaql_strict_compliance" value="false"/>
...
Any help is appreciated
Regards