• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CMP - CMR for the same field?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?


Thanks in advance,
Kim
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kim,

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic