• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Composite Primary Key

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Just a doubt about the Composite Primary Key. Sure one has to create a Primary key class and put that in <prim-key-class> tag. But what about <primkey-field>? Do we need to have multiple <primkey-field> for each <cmp-field> which is part of the Primary Key?

Also do we need to make sure that the Primary key class instance variables are named as they appear in <cmp-field>?


Mini
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again as per the spec:

The prim-key-class element contains the fully-qualified name of an entity bean's primary key class.

The primkey-field element is used to specify the name of the primary key field for an entity with container-managed persistence.

The primkey-field must be one of the fields declared in the cmp-field element, and the type of field must be the same as the primary key type.

The primkey-field element is not used if the primary key maps to multiple container-managed fields (i.e., the key is a compound key). In this case, the fields of the primary key class must be public, and their names must correspond to the field names of the entity bean class that comprise the key.

So we need not have multiple <primkey-field> for each <cmp-field> which is part of the Primary Key. Hence ur second question not applies.

The following is the DTD entry of DD corresponding to entity element:

<!ELEMENT entity(description?, display-name?, small-icon?, large-icon?, ejb-name, home, remote, ejb-class, persistence-type, prim-key-class, reentrant, cmp-filed*, primkey-field?, env-entry*, ejb-ref*, security-role-ref*, resource-ref*)>

As per the above DTD entry prim-key-class is mandatory for entity beans and primkey-field is optional.
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To put it in another way


<primkey-field> is used when there is only one primary key field and
<prim-key-class> is used in case of a composite primarkey key.

At a time either only one of them can be used.

In case of composite primary key, the bean provider creates a primary key class and specifies the class name in <prim-key-class> tag.

Hope it helps
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Sujatha

I think <prim-key-class> element is always required whether its a single field or a composite field primary key.

Thanks
Vipin
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic