Forums Register Login

SecondaryTable Mapping

+Pie Number of slices to send: Send
Hello Everybody,

I am trying to map following tables to a single class User. Is my mapping alright? Nowhere I specify that user_roles has a composite primary key. Will this work?




create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);

create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);







Thanks,
+Pie Number of slices to send: Send
It will work if the user_name is unique in the role table.

If a user has multiple roles as the schema allows, then it may work for some situations, but is not a very good idea. A OneToMany to Role would be better.
+Pie Number of slices to send: Send
Thank you so much. I understand better now. Secondary table mapping may be used for table if they have same primary key.
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1247 times.
Similar Threads
Trying to move away from MemoryRealm to using JDBCRealm.
MySQL: how to enforce the NOT NULL constraint
MySQL JDBC Error
one-to-one mapping.
form based login example
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:18:28.