-->
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: Problems with "null" values and GenericEnumUserTy
PostPosted: Fri Jul 27, 2007 2:52 am 
Regular
Regular

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

For a while i'm using the GenericEnumUserType to map Enums: http://www.hibernate.org/272.html

Now i have a problem with "null" values! My Enum looks like that:

Code:
public enum KursArt implements GenericEnum {

   /**
    * Minimalbedingungen nicht erreicht
    */
   MINIMALBEDINGUNGEN_NICHT_ERREICHT(0, "LabelKursArtMinimalbedingungenNichtErreicht"),

   /**
    * Jahrekurs
    */
   JAHRESKURS(1, "LabelJahreskurs"),

   /**
    * Saisonkurs
    */
   SAISONKURS(2, "LabelSaisonkurs"),

   /**
    * Halber Saisonkurs, resp. Schnupperkurs.
    */
   HALBER_SAISONKURS(3, "LabelHalberSaisonkurs");

   private final Integer value;

   private final String propertyKey;

   private KursArt(Integer value, String label) {
      this.value = value;
      this.propertyKey = label;
   }

   /**
    * @return
    */
   public Integer getValue() {
      return value;
   }

   /**
    * @return
    */
   public int intValue() {
      return value.intValue();
   }

   /**
    * Label der Enum
    *
    * @return
    */
   public String getPropertyKey() {
      return propertyKey;
   }

   /**
    * @param value
    * @return
    */
   public static KursArt getInstanceByValue(Integer value) {
      switch (value) {
         case 0:
            return MINIMALBEDINGUNGEN_NICHT_ERREICHT;
         case 1:
            return JAHRESKURS;
         case 2:
            return SAISONKURS;
         case 3:
            return HALBER_SAISONKURS;
         default:
            return null;
      }
   }


So in the Database is saved "null" and if hibernate maps the enumUyterType to my model it will return 0. So even if null is saved i get the Enum "MINIMALBEDINGUNGEN_NICHT_ERREICHT;" .

This is my mapping:

Code:
@TypeDef(name = "KursArt", typeClass = GenericEnumUserType.class, parameters = {
            @Parameter(name = "enumClass", value = "najsre7.model.immutable.kurs.KursArt"),
            @Parameter(name = "identifierMethod", value = "getValue"),
            @Parameter(name = "valueOfMethod", value = "getInstanceByValue") })

/**
    * @return kursArt
    */
   @Type(type = "KursArt")
   @Column(name = "SIPAR1", unique = false, nullable = true, insertable = true, updatable = true, precision = 5, scale = 0)
   public KursArt getKursArt() {
      return this.kursArt;

}


Does somebody know how to handle that??

Kind Regards
Angela


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 4:43 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
i think it's becaue the default type of the hibernate IntegerType is a 0 and not a 'null'. So is there a Type class from Hibernate which handles these nulls correctly?


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.