-->
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.  [ 3 posts ] 
Author Message
 Post subject: Enum List UserType
PostPosted: Wed Sep 12, 2007 10:32 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
I like to persist a enum list type to a String. For example,

public enum Color {
BLACK,
WHITE,
YELLOW
}

public class MyEntity {

public List<Color> getColors();

}

For colors of BLACK and WHITE, it is persisted as string "BLACK,WHITE".

public class ColorListUserType implements UserType {
....
}

I have two questions:

1. how to tell Hibernate to use the ColorListUserType for the property "colors"?

2. how to write a query to search entities that has BLACK color?

From MyEntity e where Color.BLACK in e.colors
make sense?

Thanks very much for help.
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 10:41 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
I found the answer to the Q1.
Use @Type(type="ColorListUserType").

But I still can not figure out Q2: how to query if a Enum List contains a enum value.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
2 is not really possible I think, except if you use like %BLACK% of if you use Hibernate Search to achieve the same result

_________________
Emmanuel


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