Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes two or more primary keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "two or more primary keys" Watch "two or more primary keys" New topic
Author

two or more primary keys

holger Hahn
Greenhorn

Joined: Jun 14, 2005
Posts: 9
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

Joined: Mar 28, 2005
Posts: 79
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

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."


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: two or more primary keys
 
Similar Threads
CMP maping - one to many unidirection in wl7.0
retriving two primary keys
I need a bit of explanation about bidirectional relation between two entity beans.
Same entity beans check ?
Compound map doubt