Lets say that I have a database with the following tables:
CREATE TABLE user (
user_id int NOT NULL AUTO_INCREMENT开发者_Python百科,
...
PRIMARY KEY (user_id)
);
CREATE TABLE action_x (
action_x_id int NOT NULL AUTO_INCREMENT,
...
not_the_same_columns_as_for_action_y,
user_id int,
PRIMARY KEY (action_x_id)
);
CREATE TABLE action_y (
action_y_id int NOT NULL AUTO_INCREMENT,
...
not_the_same_columns_as_for_action_x,
user_id int,
PRIMARY KEY (action_y_id)
);
The relationship is, user <=[1:M]=> action_x and user <=[1:M]=> action_y.
The 'user' table contains data of the user(s), such as login and password for example. The 'action_one' and 'action_two' tables contains data for two different actions. The actions is so unlike each other so they has to be separated into two tables.
- To summarize, 1 user can have 0 or MORE action_x records and 0 or MORE action_y records.
My problem is that I would like to implement (by storing appropriate data in the database) a way to tell the user which action(s) she or he shall perform in a specific order.
- For example, user_id=1 shall perform action_x_id=2, after that, action_y_id=1, then action_x_id=10, and so on.
I'm using MySQL as database source, with Hibernate 3.6.x and Java.
Is there any standard way to handle problems like this? How would you solve the problem?
Thank you for you help and have a nice day! =)
I would introduce one more table. Let's name it GeneralAction and set the user FKs to the table. So the filed should be
general_action_id
user_id
action_x_id
action_y_id
For each record in the table action_x_id or action_y_id is null
精彩评论