> 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:
>Or should every table-entry
> modelled with a separate entity-bean where the
> relation is handled through a session-bean?
You will find some answers in the following articles.
Note that "Aggregate Entity" pattern is renamed to "Composite Entity" in the published book.
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:
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.
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
> In the paymentType case, can I have any way to
> 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 ;)
I understand now.
From my [limited] understanding, CMP 2.0 helps with all of these functions at the expense of less control.