Page 1 of 1

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

Posted: Thu Nov 15, 2018 3:34 pm
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.

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

Posted: Sat Jan 05, 2019 1:01 am
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;
    ...
  }