Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two or more primary keys

 
holger Hahn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I work on a project and we use Enterprise Java Beans with MySql database
The problem is that one table has two primary Keys but in the entity Beans only one primary Key class can be implemented. How to solve the problem if there are more than one primary key

thank you for your support
 
Jeremy Hsu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to create a primary key class to wrap the two primary keys into this primary key class. Lookup the topic complex primary key on EJB, I bet you can find more information on this.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Holger,
Welcome to JavaRanch!

Originally posted by holger Hahn:
The problem is that one table has two primary Keys but in the entity Beans only one primary Key class can be implemented.

First let's clarify what this means. If it means a primary key with two fields, you can do what Jeremy suggested. Taken literally, it sounds like you have two primary keys, either of which is unique. This isn't supported by most databases and cannot be done in EJB. Instead, you implement a unique constraint in the database for the second "primary key."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic