-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problems with Enums mapped via CollectionOfElements
PostPosted: Thu Jul 07, 2011 7:41 am 
Newbie

Joined: Thu Apr 01, 2010 6:36 am
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.