Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Hi,
I have the following scenario. These are my tables:
-------------------------------
| USER |
-------------------------------
| PK | ID |
| VARHCHAR | USERNAME |
| VARCHAR | PASSWORD|
--------------------------------
-------------------------------
| ROLES |
-------------------------------
| PK | ID |
| VARHCHAR | USERNAME |
| VARCHAR | ROLENAME |
--------------------------------
- Implementation is in MySQL 5.0.
- I am using hibernate 3.1 on Java 1.5
- Note that the link between the user table and the roles table is through the USERNAME column.
- The default value for ROLENAME is "administrator" (In fact, this is the only role)
- Assume that we have a class User with properties username and password
- We are not really interested in mapping any values from the ROLES table (including ROLENAME)
How can I make hibernate add, delete and update the ROLES.USERNAME every time the USER.USERNAME is modified? So far I have looked at:
- one-to-one mapping of ROLES>ROLENAME to class User (added property String rolename) using/not using the property-ref attribute
- join mapping, using/not using the property-ref attribute
For the people that are interested, this particularly nasty database schema is forced upon you if you choose Tomcat 5 container-based authentication. No way around it....
Thanks!
Sincerely,
Henrik Pettersen
Advanced Computational Laboratory
Cancer Research UK