Hi Shreedhar,

Is there any limitation on not making 'x' as the primary key of the bean? If
'x' is the primary key of the bean, it is the responsibility of the
container to manage unique values. If I have got your problem correctly, 'x'
cannot be part of the compound key, as the value of 'x' alone can be
repeated {(pk1, x1), (pk2, x1) etc...}.

I think you can take two approaches.

1. Optimistic

If you know there are few instances of such collisions (supplied value of
'x' already in use), then you can supply unique constraint at the database
level for the corresponding mapped column. When a duplicate value is
provided, the database insert would fail. The caller would receive a System
Exception (depending on the conatiner).

2. Pessimistic

I guess options mentioned by you should work, but it should be used only
when the chances of supplied values to be in use are high. Option1 would be
less expensive if the your EJBContainer uses relationship cache and data for
B table is created using the application. Option2 would be less expensive if
you are working on an existing data for B bean in the database.

Hope this is of help!

Regards,
Hemant
www.pramati.com




----- Original Message -----
From: "shreedhar" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 22, 2002 10:27 AM
Subject: CMP 2.0, a problem HELP


Hello Everybody,

I have container managed relationship between two entity beans say A and B.
The relationship between A and B is 1 --> *

B has only local inteface. It is only through Bean A, Bean B is created.

Now I have field say x in the the Bean B which is not a primary key field.
While creating Bean B thru Bean A,  the values in the x should NOT be
duplicated (with respect to  A's Primary Key Field). hope u get this.

Now I have two straight forward options.

Option 1: I can iterate through the collection(CMR Field)  in the Bean A and
compare the value of x that will be used in the creation of  new instance of
B with the already present instance possible by using getX() on each
instance in the Collection maintained in A.

Option 2: use ejbSelect, join the two tables and find for an instance of B,
which already has value of x which is equal to the new value of x. I feel
this approach is very costly as it will require cartesian product.

Option 1 is also not appreciated, since I have to iterate thru the
collection of home interface and make a method call  in each instance and
compare.

If it had been CMP 1.1, I knew the relationship field name in Bean B, so
this task can be easily achieved with a simple Finder in B.

Please let me know, the best possible approach for my problem.

it will be great, if someone is able to HEEEEEEEEEEEEEEELP me.

Thanks in advance.

Shreedhar Natarajan.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to