This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JPA Certification (OCEJPA) and the fly likes Collection mapping of Elements in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "Collection mapping of Elements in JPA" Watch "Collection mapping of Elements in JPA" New topic
Author

Collection mapping of Elements in JPA

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

This is regarding an example from the JPA book.



Where VacationEntry is marked with an Embedable annotation. My question is:

Is the Embedded annotation optional and that the ElementCollection is enough to make the Persistence Provider to be aware that vacationBookings is of Embedded type?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Tamas Polgar
Greenhorn

Joined: Apr 27, 2011
Posts: 13
Hi there,

From JPA spec (http://download.oracle.com/javaee/6/api/javax/persistence/Embedded.html)
"Specifies a persistent field or property of an entity whose value is an instance of an embeddable class. The embeddable class must be annotated as Embeddable. "

For me it means you should use it for single attributes, not collections. Howewer, the annotation api doesnt deny it, and with eclipselink, and hibernate it works for me.
but in the xml api, which is better-defined, its not allowed.

So I think you should not use it,
the generic type, or the targetClass attribute of @ElementCollection is enough.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Collection mapping of Elements in JPA
 
Similar Threads
Element collections and Map relationships
org.hibernate.MappingException: Unknown entity: java.lang.String<< how can i solve
Composite key in collection of basic type
A sense of style: @OneToMany or @ElementCollection?
embedded class question