-
1. Re: Design question for Entity-Beans
minamoto Oct 14, 2001 10:09 PM (in response to joachim)> Can someone give me a tip or point me to some
> documentation about how to model a relation between
> database tables into entity-beans?
The following tip is usuful for mapping between db colums and methods.
Designing Entity Beans for Improved Performance:
http://developer.java.sun.com/developer/technicalArticles/ebeans/ejbperformance/
>Or should every table-entry
> modelled with a separate entity-bean where the
> relation is handled through a session-bean?
Not always.
You will find some answers in the following articles.
J2EE Patterns:
http://developer.java.sun.com/developer/restricted/patterns/J2EEPatternsAtAGlance.html
Note that "Aggregate Entity" pattern is renamed to "Composite Entity" in the published book. -
2. Re: Design question for Entity-Beans
andreas Oct 15, 2001 3:39 AM (in response to joachim)Hello Joachim,
relations between entities ougth be handeld whith an persistance framework. Except proprietary ones, the new ejb 2.0 spec. defines relations. See i.e. part II of this doku:
http://www.mvcsoft.com/documentation/PersistenceManager.pdf -
3. Re: Design question for Entity-Beans
haytona Oct 15, 2001 5:07 PM (in response to joachim)I wrote a short tutorial when I was working out how to implement relationships between entity ejbs. It is only CMP 1.1 support i.e. no CMR but it works for me. You just need to program in the integrity rules. I.e. if you delete parent object then all child objects get deleted.
You can see the tutorial @ http://www.geocities.com/haytona/reltut
hope it helps somewhat. -
4. Re: Design question for Entity-Beans
oytan022 Oct 16, 2001 3:29 PM (in response to joachim)Hi, haytona
I worked on CMP for some time. I always have the question about some relationship and how to implment them. When I design an enetity bean to model a base table, e.g, paymentType table, I always feel difficult to implemnet the remove(). In my opinion, no one can call the remove(), bcause it will remove all beans which have reference to it, they maybe a ten thousands records. Unlike order and orderLine, removing an order will affect limited orderLine. In the paymentType case, can I have any way to restrict to invoke remove(), or don't need a paymentType bean, because we hardly use create() and remove(), the paymentType table only has less than 10 records. we can directly operate on db.
Thanks in advance -
5. Re: Design question for Entity-Beans
haytona Oct 16, 2001 7:10 PM (in response to joachim)> In the paymentType case, can I have any way to
> restrict
> to invoke remove(), or don't need a paymentType bean,
> because we hardly use create() and remove(), the
> paymentType table only has less than 10 records. we
> can directly operate on db.
If I understand your situation you have a payments ejb/table and a paymentType table/ejb. A payment entry has a specific payment type. Each paymentType can have many (potentially thousands) of payments of that type.
Assuming this, you could do the following:
1) If a payment type was to be deleted then you could check to see if there are any payments for that type, If there were payments then throw a DeleteException of some sort. So basically you can only delete a payment type which has no payments.
2) Make a utility method to search and replace payment types if needed. Otherwise to delete a payment type you would need to delete all payments first.
The relationship between payments and paymentType is different to Order and OrderLine. OrderLine/Order have a strong relationship (aggregation i think) and an orderline cannot exist without an Order. Payment/PaymentType is not as strong. A payment type can exist without any payments. Effectively PaymentType is a lookup table.
For preventing access to remove() I think you can use the ejb-security stuff and only allow an administration role to call the remove() method for example. Try the JAAS howto in the jboss manual.
Hope this helps. Sorry if i've confused you ;) -
6. Re: Design question for Entity-Beans
oytan022 Oct 16, 2001 9:10 PM (in response to joachim)Thanks, haytona.
I understand now. -
7. Re: Design question for Entity-Beans
haytona Oct 16, 2001 9:32 PM (in response to joachim)From my [limited] understanding, CMP 2.0 helps with all of these functions at the expense of less control.