File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Collection of components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Collection of components" Watch "Collection of components" New topic
Author

Collection of components

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
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 ?.

2) 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.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Hi Friends,
Please do help me in clarifying my concepts


Thanks and Regards,
Siddharth Bhargava.
Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
Hi Sid,

1) Is Image a component OR is Image a value type?


This is some what true I would say. If the life cycle of one object is governed by another entity, hibernate terms it as component, which is as also a kind of 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 ?.


Did not understand what exactly you meant by saying "collection of JDK value types" but mapping a collection (Set,List...) is kind of same. The only thing that differentiates is 1) if the objects in the collection have their own primary key and 2) the way you achieve mapping.

If the collection if of simple value types for ex... Set<String>, one can use elements but if the collection is of complex value type for ex. Set<Address>, then one has to go for <composite-element>.

I do not have Gavin's book handy with me rt now. So probably if you ask your doubts by quoting examples/entities and than base your questions on them, I guess it would be easy for us to solve the concerns.

Regards,
Naresh Waswani


Naresh Waswani
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Hi Waswani,
Thanks for your reply.



This is some what true I would say. If the life cycle of one object is governed by another entity, hibernate terms it as component, which is as also a kind of value-type.


During the past few days I read, re-read the topic several times and understood that Image is considered a value type but when mapping in an xml it is mapped as a component.


Did not understand what exactly you meant by saying "collection of JDK value types" but mapping a collection (Set,List...) is kind of same. The only thing that differentiates is 1) if the objects in the collection have their own primary key and 2) the way you achieve mapping.


By collection of JDK value types I meant was for e.g. String, Integers, etc.


If the collection if of simple value types for ex... Set<String>, one can use elements but if the collection is of complex value type for ex. Set<Address>, then one has to go for <composite-element>.


I understood that if we have simple value types then we would use <element> tag but if the collection is a component e.g. Address then we have to map it using <composite-element>. This is clear now.




Thanks and Regards,
Siddharth Bhargava.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection of components