-->
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 GenericEnumUserType
PostPosted: Tue Sep 05, 2006 10:20 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.3
Mapping documents:
Code:
<typedef name="Status" class="com.foo.dao.GenericEnumUserType">
   <param name="enumClass">com.foo.model.Response$Status</param>
   <param name="identifierMethod">toInt</param>
   <param name="valueOfMethod">fromInt</param>
</typedef>
<class name="com.foo.model.Response" table="response">
.
.
.
   <property name="status" type="Status" column="response_status" />

Full stack trace of any exception that occurs:

Code:
org.hibernate.MappingException: Could not determine type for: com.foo.dao.GenericEnumUserType, for columns: [org.hibernate.mapping.Column(response_status)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
        at org.hibernate.mapping.Property.isValid(Property.java:185)
        at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
        at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)


I'm implementing the "flexible" enumeration user type as described in http://hibernate.org/272.html. As far as I can tell I've followed the instructions to the letter and yet I can't get it working. My class looks like this:

Code:
public class Response implements Serializable {

    public enum Status implements Serializable {
        New(0), Read(1), Unknown(-1);
        int value;

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

        public Status valueOf(int value) {
            switch (value) {
                case 0 : return New;
                case 1 : return Read;
                default: return Unknown;
            }
        }

        public int toInt() {
            return value;
        }
    }
.
.
.
}


Any thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 11:09 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
Sorted it. I modified GenericEnumUserType to implement UserType as well as ParameterizedType.

Isn't this something that should be documented or have I still done something wrong?


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.