These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: model and mapping problem
PostPosted: Fri Aug 15, 2008 3:43 am 
Newbie

Joined: Fri Aug 15, 2008 3:33 am
Posts: 17
Hi,

I have a problem concerning Hibernate. I work at an application which is based on Hibernate and MySQL as persistence layer.

But I don't know how I should modell the following problem:
I have 4 tables:
1. User - contains information for log in;
2. Manufacturer_employee
3. Retailer_employee
4. Other_employee

The last 3 tables are very similar and store some information about an employee, as: address, phone, etc. But there are also some fields which are different from employee to employee. For this reason I want to keep the employee separated.

All users are connected with an employee but not all employees are users.

How can I model this from the database view and from the persistence (hibernate) view?

I hope that I presented my problem in a proper manner and that someone can give me some hints.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 15, 2008 12:25 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Have a look at my answer in this thread

http://forum.hibernate.org/viewtopic.php?t=989709

For the inheritance mapping you can go for single table which would give you one A/User table plus one Role table containing all the attributes from the different roles you have.

regards
Jens

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 3:52 am 
Newbie

Joined: Fri Aug 15, 2008 3:33 am
Posts: 17
Hi schauder,

Thank you for your reply.
I think also that this is the best solution for my problem. But I read that table per concrete class inheritance should be avoid if there is an association from role to A as in your case.

In any case I will try this solution but please write also the database schema for the 3 tables. I want to see how the fields are mapped to the database.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 6:49 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Quote:
I read that table per concrete class inheritance should be avoid if there is an association from role to A as in your case.


Where did you read that? And what is the reason given?
The only 'problem' I know is with the ability (or lack thereof) of hibernate to create FKs and not null constraints. But I wouldn't rate those to high, and the problems can be solved in many cases by custom constraints (at least with Oracle)


if you don't go with single table inheritance but with inheritance per class you would get

- one table for Role containing the common attributes (at least the reference to A)
- one table for B and C each, containing the unique attributes of each class

If you where referring to the actually mapping (Annotations / xml) I have to refer to the documentation.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 3:53 am 
Newbie

Joined: Fri Aug 15, 2008 3:33 am
Posts: 17
I read that in the book "Java Persistance with Hibernate". This book is the second edition for "Hibernate in Action". I think in chapter 6 the author talk about the inheritance. He starts presenting the inheritance beginning with the bad model and continuing with the better ones.

And the order is that:
1. TABLE_PER_CLASS
2. TABLE_PER_CLASS with union
3. SINGLE_TABLE
4. JOINED
(the last one is the best solution from his point of view).

And talking about TABLE_PER_CLASS strategy he stated that this strategy should be avoided when there is an association between other class and the parent abstract class. He ddin't give a proper reason for that or maybe something connected with the unions which should be made in order to interogate the entire hierarhy.

In any case, I stick with this strategy because I think it is good for my case. I didn't want to have the employees in the same table, and I don't have so many different fields (max 2 for the moment) between subtables to use SUBCLASS (JOINED) strategy.

Right now I am more concert about the DAO class.
How should they look? It will be good if you can provide me an example.

Thank you for your tips.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.