• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

two or more primary keys

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic