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

About my exam cloud mock 2, @CollectionTable

Ranch Hand
Posts: 1749
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Table                                  Entity
CUSTOMER - Primary Key : CUST_ID        Customer
ORDER - Primary Key: ORDER_ID           ORDER
ORDER_ID; other  columns :Order_Date

For each customer, you want to keep the order date for each of the order. You want to keep it as a Map in Customer entiy.

Which of the following options correctly declares this field in Customer entity code?
A. @ElementCollection
  @Column (name="ORDER_DATE")
  private Map<Order,Date> orders;

B. @Entity
  public class Customer{
  private Set<Order> orders;
 private Map<Order,Date> orders;

Given answer A.
A declares a correct way to model a many to many relationship when the relationship itself has one
additonal attribute. There is a many to many relationshop between customer and order and each such
relationship has attribute orderDate.
CUST_ORDERS is a join table , but with addtional column for order date that can be captured as
a Map value. The mapping for the key of the map (ie Order) is specified using @CollectionTable,
while mapping for the value of the map (ie Date) is specified using @Column.

I think the correct way is:
Map<Order,Date> orders;

If @MapKeyJoinColumn is not specified, by default, the map key join column is "ORDERS_KEY" (the name of the property or field concat with "_KEY").
But in the CUST_ORDER table, there is no column with name ORDERS_KEY.

Creator of Enthuware JWS+ V6
Posts: 3293
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also need to override the default mapping for the foreign key column of Customer:

sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!