-->
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.  [ 1 post ] 
Author Message
 Post subject: DDD Value Objects and Hibernate
PostPosted: Sat Jan 17, 2009 9:16 pm 
Newbie

Joined: Sat Jan 17, 2009 8:06 pm
Posts: 3
Location: Montreal
Hello,

I am using hibernate to support my domain driven design project. I am currently trying to map my domain model to a normalized database.

The problem:

In my domain model, Address is an immutable value object. I want to be able to freely create them in the domain model. In other words, I don't want my domain model tracking value objects. I don't want the overhead of sharing these value objects. Instead, I want them to be freely created (copied instances of the same value).

NOTE I am referring to Eric Evans DDD Value Objects, not J2EE.

However, because my db is normalized, copies of value objects are causing problems when I commit().

The exception thrown: "a different object with the same identifier value was already associated with this session"

I should add; in the db, ADDRESS is identified by pk(street, buildingNumber, apartmentNumber, postalCode, city) and USER_ADDRESS is the mapping (relationship) table between USER and ADDRESS, where userId identifies USER. Hence, the Address object is identified by all of its attributes using <composite-id> (and yes, I've overriden equal and hashcode).


Current Solution:

For now, the only solution I got is a "find or create" method whenever dealing with shared value objects. I am not to crazy about this, cause it will increase the number of db calls.

Question:

Is there a Hibernate solution to this? is there a way that Hibernate can make value objects sharing in the db level, transparent to the domain ?

_________________
Thanks,
Arturo


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

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.