This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Concatenated Primary Key For CMP With CMR

 
Jason Mowat
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I was wondering if it is possible to have a concatenated primary key for an entity bean where part of the primary key is a reference to another entity via CMR in the same bean?

For example, imagine I have a bean called HouseBean, and I have another bean called PartyBean. A house can host zero or more parties. However, a party must have at least one house (one to many relationship). A party is unique based on a party date and for the house it is held at. The tables look as follows:

tbl_party
=========
party_date (PK)
house_id (PK)
party_type (birthday, wedding, etc)

tbl_house
=========
house_id (PK)
address
...

HouseBean is simple enough to create. It has a CMR relationship to PartyBean on the many side.

PartyBean on the otherhand gets a little more tricky. PartyBean theoretically participates in a CMR relationship with HouseBean. And PartyBean's uniqueness is enforced by a concatenated primary key consisting of a start date and the house ID that the party is being held at in the database.

Can I create a primary key class consisting of a start date and a house ID, but not define the houseId as a persistent field in the PartyBean and define it as a CMR to HouseBean instead? If so, how do I get the database to recognize that the houseId from the HouseBean CMR is part of the primary key?

I am not sure this is possible to do? Any suggested references that illustrate the solution to this problem is more than welcome!

TIA,
Jason
 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According with spec on pag 298,

spec

All fields in the primary key class must be declared as public.
The names of the fields in the primary key class must be a subset of the names of the container-managed
fields. (This allows the container to extract the primary key fields from an instance�s container-managed
fields, and vice versa.)


So, it�s not allowed to have an PK with an CMR field. In this case, you should party_date and house_id and not the entity house.
 
Nitin Mehhta
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting situation. But in the case you have mentioned House_ID would be a CMP in the House Bean and Party Date would be a CMP in Party Bean. So why can't we make a combination of these as a primary key. I don't think it is mentioned in the specs that the primary key has to a CMP of the same Bean. I may be wrong as I have never encountered this situation practically.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic