-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Differences between Value Object and Value Type
PostPosted: Fri Oct 26, 2007 10:08 am 
Newbie

Joined: Fri Dec 02, 2005 2:48 pm
Posts: 13
Is there any similarity between Value Object and Value Type?

IMHO, the term 'sharing' in the two kind of objects is very different...

'Java Persistence with Hibernate' book says:

Quote:
The lifespan of a value type instance is bounded by the lifespan of the owning entity instance. A value type doesn’t support shared references: If two users live in the same apartment, they each have a reference to their own homeAddress instance. The most obvious value types are classes like Strings and Integers, but all JDK classes are considered value types.


String suports shared references and it's not bounded by the lifespan of the entity instance! Is String really a Value Type?

On the other hand, a Value Object suports shared references when it's immutable (like String)!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 28, 2007 5:33 pm 
Newbie

Joined: Mon Jul 09, 2007 8:04 am
Posts: 12
Location: England
Hey,

I would say that you were getting a little confused between what's going on at the database level and what's going on in your application domain.

I've just been reading chapter 6, and it was talking about Items and Bids. This might make it a little clearer.

A "value type" is something that doesn't have it's own independent life cycle, and is unique to the object to which it is linked to. If the object is destroyed, then so is the value type connected with it. As a result, value types are not shared between different objects.

An "entity type" (or value object?) is different. It has its own id in the database, and so it's own lifecycle, and can be shared.

So, to use the example of address represented as a single string...
Lets assume there is a user object, which contains an address String. Bear in mind, that this is at the *application level*.

1) you implement it as a value type.
Because this is a value type - if the user's object is deleted, then so is their address - it cannot live without the user, nor can it be shared.
Typically, this would be implemented as simply a column in the same table. You would have my name, age, address. In the same way that my age is meaningless if the row for me is deleted, the address is the same.

2) you implement is as an entity type.
This would likely be implemented in a separate table, with the user's row containing a FK to the PK of the address table containing the addresses. This would allow a) the addresses to still exist in their own right without the user and b) two users to share the same address.

So, in the same way as integer would be a value type, I would argue that String was indeed a value type. However, if you created a class that simply wrapped the string object, and gave it an id, that would make it a entity type.

I hope that's clearer - it's not something easy to explain.

MG

P.S. Disclaimer - I am only upto chapter 6 and am still learning myself. Any experienced members - please feel free to correct me.

_________________
MG


Top
 Profile  
 
 Post subject: I am a little confused too
PostPosted: Sat May 24, 2008 5:59 am 
Newbie

Joined: Mon Aug 23, 2004 7:54 am
Posts: 15
Evans:
"An object that is used to describe certain aspects of a domain, and which does not have identity, is named Value Object.
It is highly recommended that value objects be immutable. Being immutable, and having no identity, Value Objects can be shared."

Hibernate:
"Value types don’t have identifiers or identifier properties. The lifespan of a value type instance is bounded by the lifespan of the owning entity instance. A value type doesn’t support shared references: If two users live in the same apartment, they each have a reference to their own homeAddress instance."

Is there a connection between "value objects" of the domain model and the "value types" from Hibernate (data model)?

Some "value objects" could be represented as "entity types" and shared?
Or if they need persistance they are in fact "entity objects" and a "value object" should reside only in memory?
The last posibility is that "value objects" are in fact "value types" and sharing in the persistance layer means copying using a denormalized table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.