-->
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.  [ 12 posts ] 
Author Message
 Post subject: Replacement for PersistentEnum - non Serializable UserType
PostPosted: Thu Apr 29, 2004 9:29 am 
Newbie

Joined: Mon Feb 16, 2004 9:19 am
Posts: 11
Due to the deprecation of the PersistentEnum interface a tried to implement a replacement by implementing a UserType.

This solution requires the Enumeration to be Serializable but this is in my opinion not useful for Enumerations.

What is a useable replacement for PersistentEnum ???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 10:24 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A UserType.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:03 am 
Newbie

Joined: Thu Apr 29, 2004 10:55 am
Posts: 1
As compared with PersistentEnum handling in 2.1.2-, I liked the way persistent enums are implemented in Castor: enum clas just has to contain a method valueOf(String) and does not have to implement any interface. It's so easy to use! Why not using something similar in hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why shouldn't your enums be serializable? You never want to move objects containing them between tiers or put them in a HttpSession? I don't think this is a limitation.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:16 am 
Newbie

Joined: Mon Feb 16, 2004 9:19 am
Posts: 11
michael wrote:
Why shouldn't your enums be serializable? You never want to move objects containing them between tiers or put them in a HttpSession? I don't think this is a limitation.


My Class has been implemented as a typesafe enum. Therefore it has no public constructor. Because these classes are not Serializable i get ClassCastExceptions in deepCopy() because the returned Object gets typecasted to Serializable.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:19 am 
Newbie

Joined: Mon Feb 16, 2004 9:19 am
Posts: 11
christian wrote:
A UserType.


I've implemented a UserType that reimplements the PersistentEnum interface.
I've changed (some of) my HQL queries to use this new type but i get a bunch of ClassCastExceptions.

Probably it would have been a good idea to refactor my Enums one class at a time...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Make it Serializable if you get an exception. The requirement is there for a reason.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:36 am 
Newbie

Joined: Mon Feb 16, 2004 9:19 am
Posts: 11
michael wrote:
Make it Serializable if you get an exception. The requirement is there for a reason.


If this is a requirement, this should documented in the interface and documentation.

The Javadoc for UserType explizitely does not require the Types to be Serializable.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Quote:
The actual class mapped by a UserType may be just about anything. However, if it is to be cacheable by JCS, it must be serializable.


There is no other place which would require the class to be serializable, and certainly not in deepCopy()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 4:21 am 
Newbie

Joined: Mon Feb 16, 2004 9:19 am
Posts: 11
michael wrote:
Quote:
The actual class mapped by a UserType may be just about anything. However, if it is to be cacheable by JCS, it must be serializable.


There is no other place which would require the class to be serializable, and certainly not in deepCopy()


The following snippet ist part of AbstractType.class:
Code:
    public Serializable disassemble(Object value,
SessionImplementor session)
        throws HibernateException
    {
        if(value == null)
            return null;
        else
            return (Serializable)deepCopy(value);
    }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 4:25 am 
Newbie

Joined: Mon Feb 16, 2004 9:19 am
Posts: 11
michael wrote:
Make it Serializable if you get an exception. The requirement is there for a reason.


I spent the time to make them Serializable and - implementig readResolve() - still kept their uniqueness. Now everyting again works as expected.

But there is still a question left:
It was convenient to use the members of PersistentEnum as a selection criteria in HQL queries. Now i have to use "query.setParamenter("xxx", value, Hibernate.custom())" instead. Is there any better way to specify them in my queries?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 4:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
The following snippet ist part of AbstractType.class:


disassemble() is only called when caching the data in the second-level cache, as Micheal said.


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