-->
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.  [ 4 posts ] 
Author Message
 Post subject: get error in Martin Kersten's flexible EnumUserType solution
PostPosted: Fri Aug 04, 2006 11:42 am 
Newbie

Joined: Tue Aug 01, 2006 1:24 pm
Posts: 1
I'm able to save my enum type via nullSafeSet but when I load via the
Code:
nullSafeGet
of Martin Kersten's flexible EnumUserType
I got the:
Quote:
object is not an instance of declaring class without
error

This happened even before my own "valueOf" method is getting called.
Can't even step into the invoke method to debug.
Can someone help why this error is coming up?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 10:15 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
hello

i have the same problem! always getting the error:

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

did you find a solutions??

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


angela


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 10:18 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
hello

i have the same problem! always getting the error:

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

did you find a solutions??

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


angela


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 10:59 am 
Newbie

Joined: Mon Jun 06, 2005 8:28 am
Posts: 5
Location: Germany
@brotherlam:
Try to declare your valuOfMethod as static like this:
Code:
public [color=darkred]static [/color]UnterrichtsDauerEnum fromInt(int value) {

_________________
Cd wrttn wtht vwls s mch trsr.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.