This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Taken From the Java EE 5 Tutorial

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Hello there! I'm diving into JPA, and I decided It'd be the right decision to start my training by reading the JEE 5 Tutorial. I'm kinda stuck in one of the key concepts here... Let me explain..

From the JEE 5 Tutorial

Composite primary keys must be defined in a
primary key class



From that statement I understood one must write a class(restrictions applied) in which all the fields are the Composite Key itself, am I right?

Now, among the requirements of a primary key class; I don't understand the following one(s):

[Taken from the Java EE 5 Tutorial]

A composite primary key must be represented and mapped to multiple fields or properties of the entity class, or must be represented and mapped as an embeddable class.



And...

If the class is mapped to multiple fields or properties of the entity class, the names and types of the primary key fields or properties in the primary key class must match those of the entity class.



Could someone please explain to me how these last requirements are applied to the actual Entity class?

I don't understand How does one as a programmer map the composite KEY to Multiple Fields or Properties in a given Entity class.

Thanks in advance for all the support!

Best Regards!

Jose.
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jose,

It just say that there are two ways that you can use a composite id. In both cases you need a composite primary key class, but in the first case you expose the CompositePrimaryKeyClass in the second case you just expose the fields/properties on wish the Key it's composed.



We're gonna use the same class for both of the cases



or



As you could see above, the property names must match the property names in the id key class and you have to add the @Id annotation to each of the fields in the entity class itself. More info here.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning Angel, I just read your reply, it was exactly what I was looking for, because I couldn't understand the Theory properly due to the lack of a descriptive example. I get it now, and I hope I can continue with my learning with no further gaps that require explanation.

Good work! and thanks for your time answering my question,

Good Luck.

Sincerely,

J�se
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
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
    Bookmark Topic Watch Topic
  • New Topic