-->
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: System.StackOverflowException
PostPosted: Fri Apr 07, 2006 6:48 pm 
Newbie

Joined: Fri Apr 07, 2006 11:42 am
Posts: 2
hi Experts,

I just started NHibernate some time ago, thought i take advantage of its capabilities, but i am stuck with this for some time!!!

I am using NHibernate version 1.0.2.0

Basically i am testing out the following concept: A Portfolio and a Security class linking to a PortfolioSecurity class through 2 many to one relationship. Some how when i try to test the PortfolioSecurity Class i get a stack overflow exception.

My Portfolio Class (PortfolioID is the primary key, PortfolioSecurities is to hold a collection of PortfolioSecurity objects)

Public Class Portfolio

Public Property PortfolioID() As String
Public Property ProjectedReturn() As Single
Public Property Name() As String
Public Property Description() As String
Public Property ReturnYearToDate() As Single
Public Property ReturnYearToDatePercentage() As Single
Public Property ReturnTotal() As Single
Public Property ReturnTotalPercentage() As Single
Public Property PortfolioSecurities() As IDictionary
End Class

My Security Class (SecurityID is the primary key)

Public Class Security
Public Property Name() As String
Public Property Description() As String
Public Property SecurityID() As String
Public Property LastDonePrice() As Single
Public Property PriceChangeFromLast() As Single
Public Property SecurityTypeID() As String
Public Property ResearchList() As IDictionary
End Class

This PortfolioSecurity Class is to act as the contract between the 2. i am using a composite key named PortfolioSecurityPK as the key taking in PortfolioID and SecurityID

Public Class PortfolioSecurityPK
Public Property PortfolioID() As String
Public Property SecurityID() As String

Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean


If obj Is GetType(PortfolioSecurityPK) Then
Dim temp As PortfolioSecurityPK

temp = CType(obj, PortfolioSecurityPK)
If (Me.PortfolioID = temp.PortfolioID) And (Me.SecurityID = temp.SecurityID) Then
Return True
Else
Return False
End If
Else
Return False
End If

End Function

Public Overloads Overrides Function GetHashCode() As Integer
Return Me.GetHashCode
End Function


Public Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) Implements System.Runtime.Serialization.ISerializable.GetObjectData
'empty i didnt put anything here
End Sub
End Class

Class PortfolioSecurity

Public Class PortfolioSecurity
Public Property PortfolioSecurityID() As PortfolioSecurityPK
Public Property TotalUnits() As Single
Public Property AveragePrice() As Single
End Class

i am using the codes below to test out the classess concept:

Dim newSecurity As Security
newSecurity = New Security
newSecurity.Name = "Media Ring"
newSecurity.Description = "VOIP Provider / Services"
newSecurity.LastDonePrice = 0.4
newSecurity.PriceChangeFromLast = 0.015
Security.saveSecurity(newSecurity)

Dim newPortfolio As Portfolio
newPortfolio = New Portfolio
newPortfolio.Description = "For my retirement"
newPortfolio.Name = "Retirement Portfolio"
newPortfolio.ProjectedReturn = 0.07
Portfolio.savePortfolio(newPortfolio)

Dim newPortfolioSecurity As PortfolioSecurity
Dim newPortfolioSecurityID As PortfolioSecurityPK

newPortfolioSecurityID = New PortfolioSecurityPK(newPortfolio.PortfolioID, newSecurity.SecurityID)
newPortfolioSecurity = New PortfolioSecurity
newPortfolioSecurity.PortfolioSecurityID = newPortfolioSecurityID
newPortfolioSecurity.TotalUnits = 1000
newPortfolioSecurity.AveragePrice = 1.22
PortfolioSecurity.saveOrUpdatePortfolioSecurity(newPortfolioSecurity)

I am tracing the code till the function saveOrUpdatePortfolioSecurity. i try using session .save(obj,key), .save(obj), .saveOrUpdate(obj) but they still give me the same error. my function is below

Public Shared Sub saveOrUpdatePortfolioSecurity(ByVal newPortfolioSecurity As PortfolioSecurity)
Dim trans As NHibernate.ITransaction
Dim session As NHibernate.ISession
Try
session = getNHibernateSessionFactory.OpenSession
trans = session.BeginTransaction

session.SaveOrUpdate(newPortfolioSecurity) <----------This is where i got thrown
trans.Commit()


session.Close()
Catch ex As Exception

trans.Rollback()
session.Close()
Throw ex
End Try
End Sub

This is my mapping file

<class name="IPort.Security,IPort" table="tblSecurity" >
<id name="SecurityID" column="SecurityID" type="String" >
<generator class="uuid.hex"/>
</id>
<property name="Name" column="Name" type="String" />
<property name="Description" column="Description" type="String" />
<property name="LastDonePrice" column="LastDonePrice" type="Double" />
<property name="PriceChangeFromLast" column="PriceChangeFromLast" type="Double" />
<property name="SecurityTypeID" column="SecurityTypeID" type="String" />
<set name="ResearchList" >
<key column = "ResearchID" />
<one-to-many class="IPort.Research,IPort" />
</set>

<joined-subclass name="IPort.Stock,IPort" table="tblStock" >
<key column="SecurityID" />
<property name="MarketCapitalisation" column="MarketCapitalisation" type="Double" />
<property name="LastUpdatedDate" column="LastUpdatedDate" type="DateTime" />
<property name="BuyVolumeTraded" column="BuyVolumeTraded" type="Double" />
<property name="SellVolumeTraded" column="SellVolumeTraded" type="Double" />
<property name="TotalVolumeTraded" column="TotalVolumeTraded" type="Double" />
<property name="OpeningPrice" column="OpeningPrice" type="Double" />
<property name="DayHighPrice" column="DayHighPrice" type="Double" />
<property name="DayLowPrice" column="DayLowPrice" type="Double" />
<property name="StockSymbol" column="StockSymbol" type="String" />
</joined-subclass>

<joined-subclass name="IPort.Fund,IPort" table="tblFund" >
<key column="SecurityID" />
<property name="FundManager" column="FundManager" type="String" />
<joined-subclass name="IPort.IndexFund,IPort" table="tblIndexFund" >
<key column="SecurityID" />
<property name="IndexFollowed" column="IndexFollowed" type="String" />
</joined-subclass>
</joined-subclass>

</class>

<class name="IPort.Portfolio,IPort" table="tblPortfolio" >
<id name="PortfolioID" column="PortfolioID" type="String" >
<generator class="uuid.hex"/>
</id>
<property name="Name" column="Name" type="String" />
<property name="Description" column="Description" type="String" />
<property name="ProjectedReturn" column="ProjectedReturn" type="Double" />
<property name="ReturnYearToDate" column="ReturnYearToDate" type="Double" />
<property name="ReturnYearToDatePercentage" column="ReturnYearToDatePercentage" type="Double" />
<property name="ReturnTotal" column="ReturnTotal" type="Double" />
<property name="ReturnTotalPercentage" column="ReturnTotalPercentage" type="Double" />
<set name="PortfolioSecurities" inverse="true" >
<key column = "PortfolioID" />
<one-to-many class="IPort.PortfolioSecurity,IPort" />
</set>
</class>



<class name="IPort.PortfolioSecurity,IPort" table="tblPortfolioSecurity" >
<composite-id class="IPort.PortfolioSecurityPK,IPort" name="PortfolioSecurityID">
<!--<key-property name="SecurityID" />
<key-property name="ResearchID" column="ResearchID" />-->

<key-many-to-one name="PortfolioID" column="PortfolioID" class="IPort.Portfolio,IPort" />
<key-many-to-one name="SecurityID" column="SecurityID" class="IPort.Security,IPort" />
</composite-id>
<property name="TotalUnits" column="TotalUnits" type="Double" />
<property name="AveragePrice" column="AveragePrice" type="Double" />
</class>

<class name="IPort.Research,IPort" table="tblResearch" >
<!--<id name="SecurityID" column="SecurityID" type="String" />-->
<id name="ResearchID" column="ResearchID" type="String" >
<generator class="uuid.hex"/>
</id>


<property name="Name" column="Name" type="String" />
<many-to-one name="Security" column="SecurityID" class="IPort.Security,IPort" cascade="save-update" />

</class>

This is the error msg: Message "Exception of type System.StackOverflowException was thrown." String


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.