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.  [ 2 posts ] 
Author Message
 Post subject: Embedable component needs access to owning entity
PostPosted: Mon Aug 25, 2008 4:32 am 
Newbie

Joined: Wed Aug 06, 2008 3:57 am
Posts: 7
Location: Malaysia
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.26.GA

Hello,

I'm hoping Hibernate will be able to facilitate the following scenario.

I've extract a set of related properties into a component (@Embeddable) class.

Now I'd like to add a method on my component class that performs a computation. The parameters for the computation are mostly from the component class, but I also need one or two properties from the 'owning entity' - the class which contains my component.

The basic rationale is for

a) rich, 'domain driven' objects and
b) perform the computation nearby to where all the relevant data is.


Of course I could remap the attributes that I need with insert="false" update="false", but that leaves me with:

* Duplicate in both the code and the mapping file.
* Having to update the component class when the owning object changes.



Thanks,

Jasper


Top
 Profile  
 
 Post subject: ah - here it is
PostPosted: Mon Aug 25, 2008 5:00 am 
Newbie

Joined: Wed Aug 06, 2008 3:57 am
Posts: 7
Location: Malaysia
The <component> element allows a <parent> subelement that maps a property of the component class as a reference back to the containing entity.

<class name="eg.Person" table="person">
<id name="Key" column="pid" type="string">
<generator class="uuid"/>
</id>
<property name="birthday" type="date"/>
<component name="Name" class="eg.Name" unique="true">
<parent name="namedPerson"/> <!-- reference back to the Person -->
<property name="initial"/>
<property name="first"/>
<property name="last"/>
</component>
</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.