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: Access a Component from class the property is implemented in
PostPosted: Fri Apr 25, 2008 9:50 am 
Newbie

Joined: Thu Apr 24, 2008 12:40 pm
Posts: 1
[b]Hibernate version: 1.2[/b]

Hello,

I have a class with the following Property relationships (each property is itself a class, except the last one ("ValueInTable") which is a string type):

MainClass.Property1.Property2.ValueInTable

There is no inheritance between the classes and the final property in the chain "ValueInTable" is the property I'm trying to access/load via the mapping file and it is in the same table as all the other properties in the MainClass object.

The following mapping using Component works just fine for inserting and retrieving data:

<component name="Property1" class="Class1">
<component name="Property2" class="Class2">
<property name="ValueInTable" column="ColumnName"/>
</component>
</component>

My problem is that when accessing/setting the "ValueInTable", one of the classes up the chain (Class1) needs to be instantiated BEFORE actually setting "ValueInTable" (this is because I have some other parameters necessary that I pass in through the higher level class's declaration of the Class2 object via the constructor) -- in other words, I'd prefer to access the "ValueInTable" ONLY through the default constructor for Class2 called from Class1 (the instance of Class2 is actually set as a private member in Class1 and uses the default constructor with parameters for Class2). However, the above mapping directly sets the "ValueInTable" from the database without instantiating Class1 (hence, the private member variable for Class2 never gets it's default constructor called).

Is there a way to alter the above mapping to force accessing "ValueInTable" only AFTER the higher-level classes in the chain (Class1 -> Class2) have been instantiated? I've tried several options and at the moment I'm trying to use the "access:ClassName" strategy - but I've never created a custom PropertyAccessor before and don't know how. Is there an nHibernate way to do this?

Thanks.


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.