• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Beginner Problem: son & parent

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have 2 tables : STAFF & MANAGER, MANAGER is a extension of STAFF (1-1 relation).
they need to map to 2 objects: staffInfo & ManagerInfo, again ManagerInfo extend staffInfo,
Assume that there may have more objects & tables extend from staff in the future.
How should i implement the staffBean and managerBean ?
My Idea is use a Session bean method: StaffInfo getStaffInfo(staffID){} :
-to get a staffInfo from staffBean,
-use findByStaffId in ManagerBean see if it is a manager,
-convent the staffInfo to managerInfo and return
this sounds not like a good way.... please help.
Lester
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me babble something about ur design, before the experts come in with the correct comments....
Both ur objects STAFF and MANAGER sound like business objects to me. So by the book, they are supposed to be modelled as Entity beans.(i.e. if you have already decided to go for EJBs). EJB2.0 CMP supports relationships,
so you can have a one-to-one or one-to-many relationships.It could be unidirectional or birectional.
I do not know ur businees requirements, so cannot be certain. I imagine they could have a bidirectional one-to-many relationships from MANAGER to STAFF.
one STAFF (1 employee) can have only 1 manager but one MANAGER could have a 1 or more STAFF objects, a collection of STAFF (employees). You could define transfer objects for both MANAGER and STAFF Entity beans to get the details of the objects at the client side, so that the number of remote calls are reduced. If you have some business logic to be performed between MANAGER and STAFF objects, you could define a 3rd EJB, a SLSB EJB acting as a session facade to the entity bean objects. The client interacts with the session bean and the session bean in turn interacts with the entity beans, so that the number of remote calls and direct access to the entity beans is restricted.
 
Lester Tam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vish Kumar, but the relationship between staff and manager in my system are not the one u mentioned.
The staff and the manager are the same person, like "Peter", ID=00142 "is a" staff and also "is a" manager, the system do not require to show who is who's manager in the relation.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I interpreted the 2 business objects as being associated to 2 different tables in the database, hence 2 different entity beans.
Though there may not be a business need to show the relationships to the end user, it may be better to consider
the relationships into design.At the database level, if they are 2 diff. tables, they could still be related together
thru the foreign key and other constraints.
If it is just one table containing both Manager and Staff records, then we may have to think about having only one entity bean,
with additional redundant attributes, which may not be a good design, especially if the attributes applicable only to
Manager/Staff Object is more.
 
Lester Tam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm... maybe i use another way to ask my question, my problem is:
I got a table, maybe we call it USER this time. which store the users in the system, but there are many type of user in the system: STAFF, CUSTOMER,VENDOR ...etc. so i have tables to store them and they are 1->1 relationship with USER and using userID as the PK.
If i want to use info objects to present the data to the font, they will be CustomerInfo,VendorInfo,StaffInfo and all these are extents from userInfo. How do i build this relationship in the bean level ?
I mean, when i give a userID to a finder method, it will return a userInfo, but if i know that user is a customer, i can cast it to CustomerInfo (no need to find again) and get the information i need.
I use this in a list box ui mainly, each row in the listbox show a user, but when i click the record, i will popup a detail window with that users type (CustomerDetailWindow,StffDetailWindow).
Im NOT concerning the relationship between a customer and a staff(2 persons) cause i think i can handle it. Im concerning someone is a user AND is a customer (same person).
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lester, Sorry, I misunderstood your problem. Let me make sure if I have got this correctly this time.
At the database layer, USER table has a relationship with other tables like VENDOR, CUSTOMER, STAFF etc.
USER table has a primarykey called userid which is the foreign key in the other tables.
Can there be rows in USER table that have a corresponding row in more than 1 table(vendor, customer, staff)?....
Is there any column in the USER table that can tell you, which type of table
(vendor, customer or staff) is it related to?
Given user information, can you navigate from the USER table to the other tables?
These questions influence your design.
Since the relationship of the USER table can be with any 1 of the other 3(or more) tables,
I am not sure if you can use CMP for this. AFAIK, CMP Entity bean relationships can be used only between
2 different tables and these 2 tables or the abstract schema cannot change at run time.
For example in your case, my assumption is that, userid 100 in USER table cam have a relationship with VENDOR table,
while userid 200 in USER table can have a relationship with CUSTOMER table and userid 300 can have a relationship with
STAFF.You may have an attribute in USER table telling you with which table is each USER row related to.
I do not know your data model fully. All this, I am just guessing......
We are talking about an entity bean having a relationship with 1 of 3 different possible entity beans at run time.
I must admit, I do not know how to do this using CMP.
A feasible approach would be, not to have any relationships at the entity bean layer.
While inserting rows into the VENDOR, CUSTOMER and STAFF tables using the individual entity beans,
consider the foreign key of the USER table also as a persistence field.I do not know if this is a good design.
You can use a session facade to implement your use cases and provide just the local interfaces for all your entity beans.
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lester -
You never mentioned using Entity beans. Are you asking how to do this using them? If so, would this be bean-managed entity beans? CMP has no way of doing this - maybe JBoss using some vendor specifics, but it sounds like you should take a look at some JDO solutions.
JDO solves many of the polymorphic database problems. There are many solutions available for JDO with relational datases, although I can't suggest one. My experience is only with the pure object database FastObjects.
Anyone have any OpenSource JDO-Relational wrappers?
 
Lester Tam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help, all.
Hmmm.. I thought that my problem is not so uncommon & unique,
As Java is kind of "OO language". I just think that there must some way,pattern maybe, to make EJB support info level inheritance (i know that bean do not support inheritance itself).
I will looking at JDO.
Thanks for the time
Lester
 
Lester Tam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vish Kumar:
I just take a look at Session facade,
It looks like the way i'm trying in my first post,
but i still have a small problem about that,
If i use a EJB relation allow other bean map to the userBean, i will by pass the session bean
eg: in orderBean: UserInfo findCustomerByUserID(String userID)
but if i change the signature to :
CustomerInfo findCustomerByUserID(String userID)
the customerBean need a way/relation to get data from userBean.
hmmm.. sounds work...
So if u want a userInfo and dont know what will return, use SessionUserBean
but if u already know what will return user the suitable bean to do the q instead, is it?
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on your requirements, you can have a single call or more to the Session bean from the client side.
The Session bean in turn could call the one or more entity beans and retrieve the data. For example: Your session bean can call UserBean to find out UserInfo and then based on this data, it could call either CustomerInfo or StaffInfo etc....
The findby methods are used only by the entity beans.
(In same cases, you can directly call an entity bean also.)
Yes, if you already know what type of user it is going to retrieve you can call the corresponding entity bean directly...The freely available online book at theserverside.com, would also be able to provide you some inputs...
 
Lester Tam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help.

Lester
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic