Hi Friends,
I was reading the section "Collections of components" in chapter 6 "Mapping collection and entity associations" of the book "Java Persistence with Hibernate" by Gavin King and Christian Bauer. I had a query in this section.
This section says "You could map image as an entity class and create a one-to-many relationship from Item to Image. However this isn't necessary, because Image can be modeled as a value type: Instances of this class have a dependent life cycle, don't need there own identity and don't have to support shared references".
Furthermore its says, "Image is a component of Item, and Item is entity that is responsible for the life cycle of Image instances. The multiplicity of the association further declares this association as many - valued i.e, many (or zero) Image instances for the same Item instance".
These 2 explanations are fine. I have some questions here :
1) Is Image a component OR is Image a value type?
2) What is the difference between components and value types ? Isn't component and value types same? Shouldn't we map the collection of components and collection of JDK value types as same? I know the difference between entity and value type. Why is <composite-element> tag introduced instead of already existing tag <element> used for value type ?.
3) What is the difference between Collection of components and Collection of JDK value types? - 6.2.2 (Java Persistence with Hibernate).
In the User and Address example in Mapping Components section in the chapter "Mapping persistence classes" in the same book would we call Address as a component OR Address as a value type? There address is taken as a component and shown to be mapped as such.
Please do resolve my queries and help me in clearing my concepts. Any help would be highly appreciated
Thanks in advance.
Thanks and Regards, Sid.
|