In order to generate the next SQL code:
create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null);
create table
Maybe in fact something like this:
This will map the roles to a collection in the User class, and roughly matches the schema you gave. It won't generate a primary key across the columns in user_roles
though.
You'll generally get better results from Hibernate with more normalised schemas though. For instance, in this case, you don't have a table for roles themselves; but what you seem to be describing would fairly naturally be modelled as a User and Role class, with a many-to-many relationship between them. Something like this:
Now this will produce a schema with tables users
, roles
and user_roles
and now user_roles
will have a primary key across the user name and role name column. You also now have somewhere to hang additional information about roles, such as descriptions.
Also, the error you're posting is a ClassNotFoundException which seems unlikely to be an actual problem with your mapping as such.
You can do this using a composite ID if you must but I'd say it's a load of pain that you just don't want to get into for something this simple.