Hi, I can't find anything in the specification about this. Do you know if it is possible to have the same field represented as both a CMP and a CMR field? E.g. sometimes you want the value for the field (the actual foreign key value) but at other times you want the relationship.
If so, then I guess it is not allowed to have a set method for the CMP field?
Did you mean whether the same db table column could be represented as both a CMP and a CMR field?
As far as I understand such representation is legal. If your entity bean is read-only bean then there are no problems.
However, the problem will arise when a bean is a read/write bean.
For instance, a client updates entity's property by calling a setter on CMP field (or cmr field) and then while still in the same transaction accesses the same entity property through a getter on CMR field. CMR field getter method will return an invalid data provided that it was not refreshed (container did not call ejbLoad()). CMR field will be still be associated with the entity property's data that used to be associated with cmp field.
Or a real life example. Account can have one Employee (many-to-one relationship, on db side Account table has a foreign constraint to Employee). AccountBean has exposed Employee as a cmp field (mapped to foreign key column) and as a cmr field (mapped to EmployeeBean's local interface). In the beginning of a transaction Account is associated with an Employee whose primary key is "12" - cmp field getter returns "12" and cmr field returns EmployeeBean (its local comp interface) with primary key of "12". While in the same transaction employee cmp field has been updated (through cmp field setter) to "24". Then in the same transaction AccountBean is asked for an employee CMR field, which did not get auto updated and therefore will return an EmployeeBean with primary key of "12".
We could do synchronization of Employee cmp and cmr fields in AccountBean (eg, when set cmp field -> find EmployeeBean by pk and set cmr field) but it does not seem as a very smart way to do things with entity beans.
In conclusion, I'd say that an entity's property should be exposed with cmp field or with cmr field but not both at the same time.
Hope it helps.
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
how do I do my own kindle-like thing - without amazon