Sorry -- I guess I'm too much of a hibernate newby to understand your answer.
In my model, RoleList is a singleton. I'd like RoleList to map to a table with a single column that contains the values from the roles field, which is a set of strings. If roles was a single string, then your suggestion (as I understand it) would work, but I don't see how to apply that principle to the situation that I'm in.
Would it be possible for you to post a .hbm.xml that might help me to understand what you have in mind?
Ah - are you saying you have a multi-valued field? Does the field contain something like a CSV list of roles?
Joined: Nov 09, 2006
I have a class, RoleList, that has a single data member called roles that is a set of strings (the class definition is in my first message).
If I were managing the JDBC manually, I would create a table named ROLES that has a single column where every row contains a single string which is the name of one of the roles. Something like this:
create table ROLES (role varchar(255) not null);
Then when I instantiate my RoleList object, I would query the db like this:
select * from ROLES;
and iterate over the result list, taking each string and putting it into the set of strings in my RoleList object.
What I'm having trouble with is figuring out how to create a RoleList.hbm.xml file that would allow hibernate to do the same thing. As you point out, using the set element in the hbm.xml file creates an association, and therefore an unnecessary table (as well as requiring an equally pointless key attribute in RoleList to allow the association to work).
Yes, a collection of values is what I'm using and it works fine. I found it hard to believe that Hibernate would require me to create a second table that would be unnecessary using straight JDBC, but it looks like that's the case.