About Question enthuware.oce-jpad.v6.2.587 :
Moderator: admin
-
- Posts: 1
- Joined: Thu Nov 15, 2018 3:31 pm
- Contact:
About Question enthuware.oce-jpad.v6.2.587 :
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.
-
- Site Admin
- Posts: 9791
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.587 :
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.
Who is online
Users browsing this forum: No registered users and 1 guest