-->
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: problem related to Foreign key on the same table
PostPosted: Fri Mar 03, 2006 2:02 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
I have the table structure like this

AccountID Code Description AccountTypeID IsActive CloseToAccountID UseCurrentFXRate

where AccountId is primary key and CloseToAccountID is foreign key withreference to AccontID column of the same table

I have the mapping file like this

<property column="Code" type="String" name="Code" not-null="true" length="50" />
<property column="Description" type="String" name="Description" length="100" />
<many-to-one name="AccountTypeid" column="AccountTypeID" class="Model.CaxAccountType,Model" />
<property column="IsActive" type="Byte" name="IsActive" not-null="true" />
<many-to-one name="CloseToAccountid" column="CloseToAccountID" class="Model.CaxAccount,Model" />
<property column="UseCurrentFXRate" type="Boolean" name="UseCurrentfxRate" not-null="true" />

And my class defination is like this

public CaxAccount()
{
_accountid = 0;
_code = String.Empty;
_description = String.Empty;
_accounttypeid = new CaxAccountType() _isactive = new byte();
_closetoaccountid = new CaxAccount();
_usecurrentfxrate = false;
}

When i m using this for ex. using NUnit for Test purpose, it gives circular reference at _closetoaccountid = new CaxAccount();
can anyone tell what is the alternative for this kind of situations


Top
 Profile  
 
 Post subject: Whay are you instantiating
PostPosted: Fri Mar 03, 2006 3:44 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Your mapping looks ok. But why are you instantiating CaxAccount for initializing _closetoaccountid. This will lead to a stackoverflow because every CaxAccount you create it will create another CaxAccount to initialize _closetoaccountid.

I think you should just let it initialize to null and have a setter method to set the property. It does not make much sense to initialize _closetoaccountid to a new CaxAccount when you are creating a new CaxAccount.
Hope this helps


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.