I was curious to how you map an entity bean to multiple tables in the database. My first idea was to simply create finder methods that map SQL in the deployment descriptors that query these mutliple tables however in the description I see a tag defining 'table'.
Is this is a good way to go about this? I need to implement entity beans that access information from multiple (existing) tables.
Any ideas would be great. I cant find examples of these in any of my books and have done some searches on the web.
Thanks
Ryan
-
How do you map one entity bean to multiple tables? (6 messages)
- Posted by: Ryan Richards
- Posted on: March 14 2002 10:04 EST
Threaded Messages (6)
- How do you map one entity bean to multiple tables? by You must leave your job on March 14 2002 20:28 EST
- How do you map one entity bean to multiple tables? by Dright Ho on March 14 2002 20:52 EST
- How do you map one entity bean to multiple tables? by stuart skinner on March 15 2002 09:17 EST
- How do you map one entity bean to multiple tables? by Java Architect on March 15 2002 09:42 EST
- How do you map one entity bean to multiple tables? by Ryan Richards on March 26 2002 08:14 EST
- How do you map one entity bean to multiple tables? by Thandaveswaran Venkatraman on March 28 2002 10:33 EST
- How do you map one entity bean to multiple tables? by Ryan Richards on March 26 2002 08:14 EST
-
How do you map one entity bean to multiple tables?[ Go to top ]
- Posted by: You must leave your job
- Posted on: March 14 2002 20:28 EST
- in response to Ryan Richards
You could 'map' to a table that is actually a view, with the view hiding all the detail - this will have cascading issues when/if you do updates through it.
You could always have fine-grain entities that are 'mapped' by application logic.
tom -
How do you map one entity bean to multiple tables?[ Go to top ]
- Posted by: Dright Ho
- Posted on: March 14 2002 20:52 EST
- in response to You must leave your job
Yes, entity beans may map to views. However, I suggest that these beans be read-only beans, since how to update and delete a "row" in a view is not defined. -
How do you map one entity bean to multiple tables?[ Go to top ]
- Posted by: stuart skinner
- Posted on: March 15 2002 09:17 EST
- in response to Ryan Richards
I presume you are looking for a way to do this in CMP. In BMP it should be relatively straight foward - on load you should be able to access both tables via some form of join and on create , remove and store you just need to perform more that one SQL query.
Stuart -
How do you map one entity bean to multiple tables?[ Go to top ]
- Posted by: Java Architect
- Posted on: March 15 2002 09:42 EST
- in response to Ryan Richards
I'm not entirely sure what you are asking. But, I would like to believe that with both CMP and BMP this should be straightforward. I would like to make a (reasonable) assumption that you have a 'domain' object per table.
So then your EB is coarse grained and made up of more than one 'domain' object. You don't really need a domain object representation, just a logical grouping of data in your EB. Also you may or maynot have 'dependent relationships', i.e. your EB could be Employee which maps to EMPLOYEE and ADDRESS tables.
With BMP, as someone pointed it out, this should be a matter of coding ejbLoad(), ejbStore(). With CMP, I would like to believe your container lets you map a particular EB field to any database TABLE as long as you can join them together.
Apologies if I misunderstood the question. Your query about writing finder methods threw me off a little. If all you are looking to do is to return a collection of data that is obtained thru joins on multiple tables, perhaps you don't need EB at all, rather just a session bean method or a 'Fast Lane Reader'
Regards -
How do you map one entity bean to multiple tables?[ Go to top ]
- Posted by: Ryan Richards
- Posted on: March 26 2002 08:14 EST
- in response to Java Architect
Thanks for all the great information. Sorry if my question was abstract. I was confused as to how to implement EB's using multiple tables. I didnt know if I was supposed to create an entity bean for every table and then use a session bean to group related joins, or if I could (and it was a good design) to create a entity bean 'object' that basically consisted of data from several tables in it's own right. For example lets assume I have the following tables:
EMPLOYEE (empid,empname)
OFFICES (officeid, address, bldg, empidfk)
Lets assume I want to have an employee bean that contains everything about him/her including the working address. I would then need to query both tables.
Scenario 1: Create a CMP table on each table and use a session bean to join them (???)
Scenario 2: Create a bean (entity or session?) that contains info from both tables to logically create one 'entity'.
Thanks
Ryan
-
How do you map one entity bean to multiple tables?[ Go to top ]
- Posted by: Thandaveswaran Venkatraman
- Posted on: March 28 2002 10:33 EST
- in response to Ryan Richards
hi Ryan,
I would suggest u to visit www.objectfrontier.com. There u can find a tool named FrontierSuite which helps u in mapping an entity bean to more than one table. You can download the trial and can work on it. This provides u to model the Classes based on UML1.3 fusing to database u prefer and can be deployed in any application servers supported by that tool.