-->
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: Configuring Enum to Integer field
PostPosted: Thu Jul 16, 2009 9:59 am 
Newbie

Joined: Mon Jan 08, 2007 6:25 am
Posts: 6
Hi All,

I've been looking around the net to no avail. I'm pretty sure im missing something simple here. I have a field in db, that is of type int. I'm trying to properly map, using annotations the enum property.


Code:
@Entity
@Table(name = "MyTable")
public class  myClass implements Serializable {

        @Id
   @Column(name = "Id", nullable = false)
   private int id;

        @Column(name="enumFieldId")
        private MyEnumType enumtype;


  /* getters & setters */
}

public enum MyEnumType {
 
   ENUM_1 (1),
   ENUM_2 (2);

   private int value;

   private MyEnumType(int value){
     this.value = value;
   }

   public int getValue () {
      return this.id;
   }

  public static MyEnumType fromValue (int value){
     //returns the one coresponding to id
  }

}




if from the the above i try to retrieve te DepositType i get

java.lang.IllegalArgumentException: Unknown ordinal value for enum class com.test.enums.MyEnumType: 23

I have the value Enum_X (23) but i dont have 23 items in the enum listing.

Any thoughts on how i can fix this?

Thanks
Nick


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.