tags:

views:

18

answers:

1

I have a Validity object which contains two dates, start and end. I have a UserType that I've written for this so that I can simplify the hibernate mappings for the several entities that have one. That works fine.

Now I want to add a set of weekdays to Validity. The only solution I can figure out is to change each entity to treat Validity as a component, with the weekdays mapped as a .

Is there some way to use do this with a *UserType?

class Validity {
  Date start;
  Date end;
  Set<DayOfWeek> daysOfWeek;
}

enum DayOfWeek {SUNDAY, MONDAY, TUESDAY ... }
A: 

Since the contents of the set come from an enum, can you map (encode) each possible value of daysOfWeek set to a database value and write a UserType instance to manage the translation? For eg something like where { SUNDAY, TUESDAY, THURSDAY } maps to 1010100.

Edit: This would make querying the database by applications other than yours a pain.

binil
This is what we've decided to do in this case, but we have other cases where it's not an enum but user-entered data and thus not possible. So I'd still like to find a general solution to the problem.
David Corbin