• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

My exam cloud mock 4, about composite primary key

 
Ranch Hand
Posts: 1749
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.
 
Skool. Stay in. Smartness. Tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!