Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

My exam cloud mock 4, about composite primary key

 
Ranch Foreman
Posts: 1897
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You are assigned to create an entity which is mapped to a table that has a primary key constraint defined on two character columns and would like to use mapping defaults as much as possible to simplify the code.
Which two mapping options can be chosen?
Choose two.
A. use @Id property that construct a private field as a concatenation of two columns.
B. use a separate class to map those two columns and use an @IdClass annotation to denote the primary key field or property in the entity.
c. Use a separate @Embeddable class to map those two columns and use @Embeddable annotation to denote a single primary key field or property in the entity.
d. use a separate @Embeddable class to map those two columns and add two fields or properties to the entity, each marked as @Id that correspond to the fields or properties in the embeddable class.
e. use a separate class to map those two columns. Specify that class using @IdClass annotation on the entity class. Add two fields or properties to the entity , each mark as @Id that correspond to the fields or properties in that separate class.
Given answer : C and E.




I think B is correct.

For example, quote the example from JPA Pro:



I think c is correct only if the statement is rephrased into:
Use a separate @Embeddable class to map those two columns and use @EmbeddedId annotation to denote a single primary key field or property in the entity.
For example in the JPA Pro:


D is not correct because we should use @EmbeddedId instead of @Id. D is correct only if it is rephrased into:
use a separate @Embeddable class to map those two columns and add two fields or properties to the entity, each marked as @EmbeddedId that correspond to the fields or properties in the embeddable class.

So, I think the final answers should be B and E.
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic