-->
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.  [ 5 posts ] 
Author Message
 Post subject: UserTypes should implement Serializable?
PostPosted: Tue Nov 23, 2004 3:24 pm 
Newbie

Joined: Mon Nov 22, 2004 5:55 pm
Posts: 5
I'm getting warnings in my log file to the effect of:
Code:
13:15:14,335  WARN CustomType:49 - custom type does not implement Serializable: class com.foo.bar.TimeIntervalUserType


My TimeInterval class implements Serializable but the TimeIntervalUserType does not. The code in net.sf.hibernate.type.CustomType seems to want the UserType to be Serializable:

Code:
    public CustomType(Class userTypeClass) throws MappingException {
        name = userTypeClass.getName();
        try {
            userType = (UserType)userTypeClass.newInstance();
        }
        catch(InstantiationException ie) {
            throw new MappingException("Cannot instantiate custom type: " + userTypeClass.getName());
        }
        catch(IllegalAccessException iae) {
            throw new MappingException("IllegalAccessException trying to instantiate custom type: " + userTypeClass.getName());
        }
        catch(ClassCastException cce) {
            throw new MappingException(userTypeClass.getName() + " must implement net.sf.hibernate.UserType");
        }
        types = userType.sqlTypes();
        if(!(java.io.Serializable.class).isAssignableFrom(userType.returnedClass())) {
            LogFactory.getLog(net.sf.hibernate.type.CustomType.class).warn("custom type does not implement Serializable: " + userTypeClass);
        }
    }


but the section in Hibernate In Action that describes UserType (Section 6.1.2) doesn't mention anything about custom user types having to be serializable. I'd appreciate it if someone could resolve the discrepency and maybe even explain why UserTypes need to be Serializable (if indeed they do).

Thanks,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 3:26 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Just make it serializable, the error message couldn't be easier to understand.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And this error message (as well as the code you have shown) means that the domain model class that is mapped _by_ the UserType has to implement Serializable. Yours doesn't, and from the exception, it looks like your UserType implementation is broken.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 3:56 pm 
Newbie

Joined: Mon Nov 22, 2004 5:55 pm
Posts: 5
Perhaps I was unclear.
    My TimeInterval class implements Serializable.
    My TimeIntervalUserType does not implement Serializable.
    The warning in the log indicates that the TimeIntervalUserType should implement Serializable
    The code snippet (from net.sf.hibernate.type.CustomType -- not my code) also indicates that TimeIntervalUserType should implement Serializable
    Your book makes no mention of custom mapping types needing to implement Serializable

My question is: which is correct -- the book or the code? The answer seems obvious, but not mentioning that custom mapping types need to be serializable seems to be a glaring omission and inconsistent with the careful detail evident in the rest of the book. I was hoping that you could confirm that UserType implementing classes also need to implement Serializable and perhaps briefly explain why.

Thanks,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 3:58 pm 
Newbie

Joined: Mon Nov 22, 2004 5:55 pm
Posts: 5
I'm sorry, you're right. I didn't read the code carefully and I see your point. Thanks for taking the time to reply.

Alex


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