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: [b]Mapping documents:[/b]
PostPosted: Mon Oct 16, 2006 4:37 am 
Newbie

Joined: Sun Oct 15, 2006 6:53 pm
Posts: 1
Location: London
Hi I'm new to Hibernate. Have borrowed the book 'Hibernate in Action' plus read the NHibernate docs but still confused as to creating mapping files.. I enclose my code. Can anyone help..?

/*
CREATE TABLE [dbo].[tblInvestment](
[InvestmentId] [int] IDENTITY(1,1) NOT NULL,
[InvestmentName] [varchar](50) NOT NULL,
CONSTRAINT [PK_tblInvestments] PRIMARY KEY CLUSTERED
(
[InvestmentId] ASC
)

CREATE TABLE [dbo].[tblAsset](
[AssetId] [int] IDENTITY(1,1) NOT NULL,
[AssetName] [varchar](50) NOT NULL,
[InvestmentId] [int] NOT NULL,
[AssetValue] [Currency] NOT NULL,
CONSTRAINT [PK_tblAsset] PRIMARY KEY CLUSTERED
(
[AssetId] ASC
)

ALTER TABLE [dbo].[tblAsset] WITH CHECK ADD
CONSTRAINT [FK_tblAsset_tblInvestment] FOREIGN KEY([InvestmentId])
REFERENCES [dbo].[tblInvestment] ([InvestmentId])
GO

ALTER TABLE [dbo].[tblAsset] CHECK CONSTRAINT [FK_tblAsset_tblInvestment]
*/

using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using Iesi.Collections;

namespace MyNamespace
{
public class Investment
{
private int id;
private string name;
private PortfolioOfAssets portfolioOfAssets;

public virtual string Name
{
get { return name; }
set { name = value;}
}
public virtual int Id
{
get { return id; }
set { id = value;}
}

public virtual PortfolioOfAssets PortfolioOfAssets
{
get { return PortfolioOfAssets; }
set { PortfolioOfAssets = value; }
}
public Investment()
{
this.portfolioOfAssets = new PortfolioOfAssets();
}
}



public class PortfolioOfAssets
{
private ISet assets = new HashedSet();
private Investment investment;

public virtual ISet Assets
{
get { return assets; }
set { assets = value; }
}

public Investment Investment
{
get { return investment; }
set { investment = value;}
}

public PortfolioOfAssets()
{}

public decimal GetPortfolioValue()
{
decimal result = 0.0M;
foreach(Asset asset in Assets)
{
result += asset.AssetValue;
}
return result;
}
}



public class Asset
{
private PortfolioOfAssets portfolioOfAssets;
private string name;
private decimal assetValue;

public PortfolioOfAssets PortfolioOfAssets
{
get { return PortfolioOfAssets; }
set { portfolioOfAssets = value;}
}
public virtual string Name
{
get { return name; }
set { name = value;}
}
public virtual decimal AssetValue
{
get { return assetValue; }
set { assetValue=value;}
}
}


}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 7:49 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Just go through the link

http://forum.hibernate.org/viewtopic.php?t=964686

-Regards
Deepak


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.