aspose file tools*
The moose likes Object Relational Mapping and the fly likes Advice for changing database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Advice for changing database" Watch "Advice for changing database" New topic
Author

Advice for changing database

Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
Hi,

I'm in a project using Hibernate (version 2.1.8) to access a DB2 database. The DB has a table storing users with various attributes (name, supervisor etc...), users can belong to one of two possible roles (user or supervisor). The primary key consists of a user ID. The table gets its data from an external system which authenticates the user while logging in.

A request was made to add an attribute "signature" which is applicable to users only; supervisors won't have or need it.

My problem is that I can't decide how to implement this request:

a) add a new table with a foreign key UserID which points to the user table and an attribute signature.

b) just add the signature to the existing user table.

Does any of the above possibilities collide with Hibernate? I tend to go with option a)
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
hi

a) you have to map a many-to-one element. To read a all the user information you (hibernate) would need to join these tables.

b) since all users are in the same table there would be a column "signature" which can not have a not null constraint.

With the information i've seen so far i would go with version b. Needs just one select to get all user informations.

pascal
Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
Why do you think of a many-to-one-relationship? The signature will be a string, and one user will have one signature.

By the way, I tend to go with option a because the current user table is filled by the external login system only. By introducing a new table for this extra information we would separate table access: Login system modifies USER table, our application modifies ADDITIONAL_INFO table. I do see that the extra table is quite a big bang solution for storing just this additional attribute. I can't name it, but somehow I have the unspecific feeling that this is good. Feel free to call me a fool
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
Mike you are a fool (hey, i'm just doing what you tell me to do :-) )

sorry. one-to-one. But I see your point with the external system. Might be better, yes. At least until you can be absolutely sure that the other application does not get upset if there is suddenly a new column in the table.


pascal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Advice for changing database