-->
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.  [ 36 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Persisting jdk1.5 enums today
PostPosted: Tue Aug 10, 2004 9:28 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Hibernate version:2.1

I am writing a lot of jdk1.5 enums and I am wondering how to persist these enums here on the brink of the Hibernate 3 release.

I have a lot of classes similar to
public enum Fruit {
APPLE,
ORANGE,
BANANA;
}

And I would like to persist relationships to such enums in the database. Since a jdk1.5 enum is just a special java class, I am certain persistence can be achieved - but what is the best way to go about it, in order to be as compatible with the coming Hibernate 3 release as possible?

I suppose this question is best answered by people who have some level of insight into the development plans for Hibernate 3, but any comments are highly appreciated.

Thanks
Randahl


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 9:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is quite easy, use a custom UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 10:02 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Sure... but I was hoping for a little insight into what will happen when the Hibernate 3 version comes out. If I use a custom UserType today, what changes should I expect to make after the Hibernate 3 release. For instance, will the next release make the custom UserType unnecessary?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 10:20 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Also, writing a custom type for each enum involves quite some development effort - is there no way arround this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 10:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Currently not. Either wait for enum suport in Hibernate 3 or use a UserType for your enums.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 2:08 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
O.k. - thanks. It is good to know if one is following the right path.
Randahl


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 10:32 am 
Newbie

Joined: Fri Mar 12, 2004 10:02 am
Posts: 16
michael wrote:
Currently not. Either wait for enum suport in Hibernate 3 or use a UserType for your enums.


Is the enum support part of the apha version or when to expect it? I really like the new features of J2SE 5 and want to use it. Hibernate support would be great.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Its not in the alpha, but will come soon. (Its trivial to implement, I guess.)

Annotations are also on their way, Emmanuel is working on that.

We can handle generics, but we don't yet use the generic type to "guess" the collection element type. We should also do that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(We should probably also genericize the Session interface at some stage.)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 2:04 pm 
Newbie

Joined: Mon May 31, 2004 9:22 am
Posts: 5
Location: Austria
We handle enum's with the following workaround, which avoids the development of UserTypes:

Code:
public class ActionConfig
{
    public enum ActionType {ENTRY_POINT, SATELLITE, POPUP_MENU, BUTTON};
   
    private ActionType type;
   
    //Only used intern, for saving the enum into the database
    private String enumType;
   
    // ...

    private String getEnumType() {
        return getType().toString();
    }

    private void setEnumType(String enumType) {
       this.setType(ActionType.valueOf(enumType));
    }

    public ActionType getType() {
        return type;
    }

    public void setType(ActionType type) {
        this.type=type;
    }
}


The property type isn't mapped at all and enumType is mapped with the following code:
Code:
<property name="enumType" column="jakt_typ" type="string"/>


Yours,
Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 11, 2005 5:44 am 
Newbie

Joined: Sat Jun 11, 2005 5:27 am
Posts: 11
You should also be able to handle enums as integer types using ordinal() etc..
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 10:52 am 
Newbie

Joined: Mon Dec 12, 2005 10:45 am
Posts: 12
It is now 6 months since the last message in this thread.

Hibernate 3.1 is about to released.

May I ask what is exactly the status of the integration of Java 1.5 enum into Hibernate 3.1 ?

Are enum correctly mapped ?
How to use them ?

Sincerely.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 12:41 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 3:35 pm
Posts: 24
Location: Buenos Aires, Argentina
Pascal jacob wrote:
It is now 6 months since the last message in this thread.

Hibernate 3.1 is about to released.

May I ask what is exactly the status of the integration of Java 1.5 enum into Hibernate 3.1 ?

Are enum correctly mapped ?
How to use them ?


AFAICT ther's not Java 5 support in Hibernate 3.1. Neither generics nor enums.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 2:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
stating that there are no support for these things sounds wrong to me since I use it everyday without problems ;)

enums can be done via usertypes and are directly supported in ejb3 and annotations project. (and with parameterized types its trivial)

Generic collections have always worked in Hibernate.

The session API haven't been jdk5'izied since it will break compability (at least for the suggestions I have seen)

The only thing I know there can be issues with is hibernate can get confused when you overload the return types, but I actually think that breaks parts of the java bean spec...so probably wise not to use that anyway with properties.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 5:19 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
max wrote:
stating that there are no support for these things sounds wrong to me since I use it everyday without problems ;)

enums can be done via usertypes and are directly supported in ejb3 and annotations project. (and with parameterized types its trivial)


With all due respect, you didn't read the reason for not doing this above. I don't want this to become a cyclical discussion.

Quote:
Also, writing a custom type for each enum involves quite some development effort - is there no way arround this?


I, too, would love to have support for this new type, without having to write more utility classes just for my mappings. It's easier to just use static finals, which I hate barely less than custom typing all my enums.

In short, please be aware that many of us still desire true enum support with Hibernate. Honestly, it's one of the only reasons I migrated to JDK 5.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 36 posts ]  Go to page 1, 2, 3  Next

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.