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

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: 8190
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Sat Jan 05, 2019 1:01 am

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 1 guest