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.  [ 2 posts ] 
Author Message
 Post subject: GenericEnumType not working
PostPosted: Wed Aug 30, 2006 8:28 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
Hibernate version:3.2 CR2

hi all

i have some problems with the flexible enum solutiion described here:
http://hibernate.org/272.html
The following error occurs when calling the nullSafeGet method:

Code:
    java.lang.IllegalArgumentException: object is not an instance of declaring class




my method looks like that:
Code:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
             throws HibernateException, SQLException {
     
          Object identifier=type.get(rs, names[0]);
          try {
                return valueOfMethod.invoke(enumClass, new Object [] {identifier});
            }
            catch(Exception exception) {
                throw new HibernateException(
                        "Exception while invoking valueOfMethod of enumeration class: ", exception);
            }
       }




My Enum class:
Code:
public enum UnterrichtsDauerEnum implements Serializable {
       Unknown(0), GROESSER_GLEICH_60(1), GROESSER_GLEICH_90(2);
       int value;
     
       private UnterrichtsDauerEnum(int value) {
          this.value = value;
       }
     
       /**
        * @return
        */
       public int toInt() {
          return value;
       }
     
       /**
        * @param value
        * @return
        */
       public UnterrichtsDauerEnum fromInt(int value) {
          switch (value) {
             case 1:
                return GROESSER_GLEICH_60;
             case 2:
                return GROESSER_GLEICH_90;
             default:
                return Unknown;
          }
       }
    }




And here the parts of my mapping file:

Code:
<typedef name="UnterrichtsDauerEnum" class="najsre7.dao.hibernate.userType.immutable.GenericEnumUserType">
             <param name="enumClass">najsre7.model.immutable.kurs.UnterrichtsDauerEnum</param>
             <param name="identifierMethod">toInt</param>
             <param name="valueOfMethod">fromInt</param>
        </typedef>
     
     <subclass name="najsre7.model.KursNutzergruppe1" discriminator-value="1">
             <property name="kursArt" type="najsre7.dao.hibernate.userType.immutable.kurs.KursArtUT">
                   <meta attribute="use-in-tostring">true</meta>
                   <meta attribute="use-in-equals">true</meta>
                   <column name="SIPAR1" precision="5" scale="0" not-null="true" />
               </property>
               <property name="unterrichtsDauer" type="UnterrichtsDauerEnum">
                   <meta attribute="use-in-tostring">true</meta>
                   <meta attribute="use-in-equals">true</meta>
                   <column name="SIPAR2" precision="5" scale="0" />
               </property>
               <property name="gruppenGroesse" type="najsre7.dao.hibernate.userType.immutable.kurs.GruppenGroesseUT">
                   <meta attribute="use-in-tostring">true</meta>
                   <meta attribute="use-in-equals">true</meta>
                   <column name="SIPAR3" precision="5" scale="0" not-null="true" />
               </property>
     
    //more




Some help appreciated! Other solutions with UserTypes and ENUM's are welcome as well.

Kind Regards
Angela


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 9:37 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
i finally found the solution! the method fromInt must be defined as static!

angela


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

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.