Mapping Problem

Hi,

I need some help in design of some database tables and theirs mapping into classes (not a Hibernate mapping).

Maybe someone can advise me.

The task is as follows:

In my software (Java + MySQL) I have two main participants: supplier and dealer.

I store suppliers and dealers in two tables:

SUPPLIER (id, name, etc)

DEALER (id, name etc)

suppliers and Dealers can have users.One user have login, password, email etc. and can log on to my reporting software.I decide to store users into one table:

USER (id, login, password, email etc)

Although I have to distinguish between supplier's users and dealer's users because I should show them different views

That's why I create a new table :

USER_MAPPING (id_user, id_supplier, id_dealer)

Only one of id_supplier or id_dealer can be not null.

So I can distinguish between both kind of users.

Question 1: What is your opinion about this design?

Question 2: Which is the best strategy to map these tables into class hierarchy?

Many thanks in advance

PS

Excuse me my english

[1143 byte] By [allex_poa] at [2007-11-27 6:35:12]
# 1

still dont understand why dealers need to have a user id and pass? besides the user_id and password what other things do you have to store in the suppliers table and delaer table?

A good way is to get use to foreign key also. i still cannot make sense out of it how a supplier and dealer have a relation? may be you meant to say link with each other like products?

fastmikea at 2007-7-12 18:02:10 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi fastmike,

Thank you for your fast reply.

No, suppliers and dealers have no connection (they are totally independent each other).

Each of them can have users.Users can log on in a web interface and can view different reportings.When a user logs on I should determine if this user is an supplier's user or an dealer's user.That's why I create the table user_mapping, which shows who is the "owner" of the user (id_supplier and id_dealer are FK's and are defined as "integer null", i.e. they can be null).So if we have user with id 2 and in user_mapping the following record (id_user, id_supplier, id_dealer) -> (2, 3, null), then the user belongs to the supplier with id 3.

Thanks

allex_poa at 2007-7-12 18:02:10 > top of Java-index,Java Essentials,Java Programming...
# 3
Can you elaborate a little on the what's, not the how's... What is a dealer, a supplier, a user. Can you explain it without using classes or tables, just responsabilities and relationships.
Peetzorea at 2007-7-12 18:02:10 > top of Java-index,Java Essentials,Java Programming...
# 4
Maybe you should add a field role to the user table instead of using a mapping table. Depending on the role you know which table to query or which view to return.
Peetzorea at 2007-7-12 18:02:10 > top of Java-index,Java Essentials,Java Programming...
# 5

Hi,

Suppliers are companies which have products.This products should be sold.Dealers are companies which sale products.Supplier delivers products but does not know which dealer sales the product.The only important thing for the supplier is the revenue.The dealer sales products and also does not know who is the supplier.And again the only important thing for the dealer is the revenue.So the software should distribute supplier's products between dealers and finally should show all the relevant revenue information in a web interface.Each of the parties (suppliers and dealers) have employees.These employees are called users in terms of my software.One employee/user can log on to the web interface and track the sales, revenues etc.

I decide to store all the users in one table, because from authorization point of view they are equivalent (for instance they can log on)

Although I should somehow distinguish between supplier's users and dealer's users (the table USER_MAPPING)

Each of the user have also roles, but these roles control just if an user can see/request some view/gui or not, they can not control the requirement that for instance dealer A can see only his own trades and not the trades of dealer B.So there exists also permission on the "data level".With the table USER_MAPPING I try to implement this requirement (permission on "data level").That is, when a user logs on, I should recognize if he is an supplier's user ot dealer's user and then I can show them just the trades for its supplier or dealer.

I hope, I managed to explain my goals

Thanks

allex_poa at 2007-7-12 18:02:10 > top of Java-index,Java Essentials,Java Programming...