This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Creation of CMP Entity bean with a Composite Primary Key??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Creation of CMP Entity bean with a Composite Primary Key???" Watch "Creation of CMP Entity bean with a Composite Primary Key???" New topic
Author

Creation of CMP Entity bean with a Composite Primary Key???

vikram karne
Ranch Hand

Joined: Jun 05, 2007
Posts: 34
Hi

i am having a composite primary keys in one of my table in the database.
I am trying to create a new entity bean for this table but i don't know how to create one in case when there is a composite primary key for a table.
Can anybody let me know is it possible to do it.
what is the procedure to be followed for the creation of the Entity bean in case of a composite primary key.

I am using MySql as the database .Creating CMP type of Entity bean.
Any help in this regard will be greatly useful to me as this is very urgent.

Thanks & Regards
Vikram K
Sunil Dixit
Greenhorn

Joined: Jun 21, 2007
Posts: 1
Hi,
It is possible in CMP and it is a peice of cake. You need to do following things :
1. create class which contains all required attribute of your composite PK and make it sure that this class implement serializable interface.
2. override equal and hashcode as per your business rule.
3. mention your class name with fully pkg name in descriptor of your entity.
4. I think tag called comp-pk ... but check in spec.

for eg.
class myPK implements Serializable
{
Intger col1;
String col2;
Inetger col3;
.... getter and setters
.. equals and hashcode....
}
hope that this help you...

Sunil
vikram karne
Ranch Hand

Joined: Jun 05, 2007
Posts: 34
Thanks a lot Sunil

i will try to carry out the same procedure as you have said.


Regards
Vikram K
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creation of CMP Entity bean with a Composite Primary Key???