About Question enthuware.oce-jpad.v6.2.587 :

Moderator: admin

Post Reply
Martin
Posts: 1
Joined: Thu Nov 15, 2018 3:31 pm
Contact:

About Question enthuware.oce-jpad.v6.2.587 :

Post by Martin »

Why is a @ElementCollection Annotation correct? It clearly states that when the map has an Entity as key, it must be a relationship Annotation. The ElementCollection is for embeddables and primitives only.

admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.587 :

Post by admin »

ElementCollection can be used for entities also. Example 2 on page 396 of JPA 2.0 specification uses it:

Code: Select all

@Entity
public class VideoStore {
  @Id int id;
  String name;
  Address location;
  ...
  @ElementCollection
  @CollectionTable(name="INVENTORY",
  joinColumns=@JoinColumn(name="STORE"))
  @Column(name="COPIES_IN_STOCK")
  @MapKeyJoinColumn(name="MOVIE", referencedColumnName="ID")
  Map<Movie, Integer> videoInventory;
  ...
}

  @Entity
  public class Movie {
  @Id long id;
  String title;
    ...
  }
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests