Hi, Can some one tell me the purpose of PrimaryKey class. I thought like if we have a PrimaryKEy class then we no need to have a PKConstraint at the database level. but if u dont have a PKConstraint at the DB level then its possible to create duplicate records even though u have a specified PKClass in the deployment discriptor. Now i would like to know the purpose of PKClass ? Doesn't it meant to maintain the uniqueness ? can some one help me out from this...Correct me if assumption is wrong.
thanks
Anil.
-
Purpose of PrimaryKey class. (7 messages)
- Posted by: Anil Kumar T
- Posted on: February 04 2002 00:23 EST
Threaded Messages (7)
- Purpose of PrimaryKey class. by Kathirvel Periasamy on February 04 2002 00:41 EST
- Purpose of PrimaryKey class. by Hemant Khandelwal on February 04 2002 07:17 EST
- Purpose of PrimaryKey class. by Gal Binyamini on February 04 2002 09:53 EST
-
Purpose of PrimaryKey class. by Hemant Khandelwal on February 05 2002 04:51 EST
- Purpose of PrimaryKey class. by Anil Kumar T on February 05 2002 07:17 EST
-
Purpose of PrimaryKey class. by Gal Binyamini on February 05 2002 01:50 EST
- Purpose of PrimaryKey class. by Hemant Khandelwal on February 06 2002 06:35 EST
-
Purpose of PrimaryKey class. by Hemant Khandelwal on February 05 2002 04:51 EST
- Purpose of PrimaryKey class. by Gal Binyamini on February 04 2002 09:53 EST
-
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Kathirvel Periasamy
- Posted on: February 04 2002 00:41 EST
- in response to Anil Kumar T
In CMP, the container will have it's own persistence framework. The PrimaryKey class is a mechanism by which u identify an entity uniquely with which u may retreive, update, create or delete. This mechnanism just maps the PrimaryKey mechanism at the database level.
To put it simple, PrimaryKey Class is the mechanism that identifies a row uniquely at the container's persistence framework level where as the PrimaryKey in the db is the same but at the database level. I just tried my best to answer ur question. -
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Hemant Khandelwal
- Posted on: February 04 2002 07:17 EST
- in response to Anil Kumar T
Hi Anil,
The specification clearly mentions that the container *may* throw a DuplicateKeyExceptionwhen an entity with the same key already exists. So a container may choose not to throw DuplicateKeyException if no database constraints are defined.
Regards,
Hemant
www.pramati.com -
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: February 04 2002 09:53 EST
- in response to Hemant Khandelwal
Hemant's note is correct, but I just wanted to emphasize the point: you can never create two entity beans with the same PK. The container is not required to throw a DuplicateKeyException, but it is required to ensure the duplicate PK never gets written to the DB. If the container didn't throw DuplicateKeyException, it will rollback the transaction before it completes. The container is allowed to delay the throwing of a DuplicateKeyException for perofrmance reasons.
Gal -
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Hemant Khandelwal
- Posted on: February 05 2002 04:51 EST
- in response to Gal Binyamini
I think the section 10.5.8.2 from the EJB2.0 final specification says it all.
"10.5.8.2 DuplicateKeyException
The DuplicateKeyException is a subclass of CreateException. It may be thrown by the Container to indicate to the client or local client that the entity object cannot be created because an entity object with the same key already exists. The unique key causing the violation may be the primary key, or another key defined in the underlying database.
Normally, the Container should not mark the transaction for rollback before throwing the exception.
When the client or local client receives a DuplicateKeyException, the client knows that the entity was not created, and that the transaction has not typically been marked for rollback."
For performance reasons, a container may choose to skip existence of a duplicate record if no database constraints are defined. In any case, DuplicateKeyException is an application exception and container is not supposed to mark the transaction for rollback.
Regards,
Hemant
www.pramati.com -
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Anil Kumar T
- Posted on: February 05 2002 07:17 EST
- in response to Hemant Khandelwal
Hi thanks for the responses. As per the aboe discussion whether to throw or not is left to container/server specific right(throwing DuplicateKeyException) ? can some tell me which server has implemented that. coz in weblogic i'm able to create the duplicate records.
thanks,
Anil. -
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: February 05 2002 13:50 EST
- in response to Hemant Khandelwal
Hemant, I belive you are looking in the wrong place. The section you mentioned describes the meaning of DuplicateKeyException, not the responsibillities of the container provider. As per sub-section 10.5.3, page 176:
"The entity object created by the ejbCreate<METHOD> method must have a unique primary key. This means that the primary key must be different from the primary keys of all the existing entity objects within the same home. However, it is legal to reuse the primary key of a previously
removed entity object. The container may, but is not required to, throw the DuplicateKeyException on the Bean Provider’s attempt to create an entity object with a
duplicate primary key[15]."
The comment [15] states that containers using, for instance, optimistic strategies, may rollback the transaction at a later point. I.e, DuplicateKeyException is not required, but the container *is* required to ensure the uniqueness of the PK by some other means.
That is what I stated in my post above. Do you have a different interpretation of this subsection of the spec?
Gal -
Purpose of PrimaryKey class.[ Go to top ]
- Posted by: Hemant Khandelwal
- Posted on: February 06 2002 06:35 EST
- in response to Gal Binyamini
no doubt about this interpretation...
Hemant