-->
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.  [ 7 posts ] 
Author Message
 Post subject: Session.save is not Working right...
PostPosted: Sat Sep 12, 2009 4:03 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 6:44 am
Posts: 24
--------------------------------This is my parent class---------------------------------

public class Item
{
private int _ITEM_ID;
private string _Name;
private string _Description;
private ISet bids = new HashedSet();

public virtual ISet Bids
{
get { return bids; }
set { bids = value; }
}
public virtual void addBid(Bid bid)
{
bid.itemvar = this;
bids.Add(bid);
}
}


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DTO" namespace="Business.Entities">
<class name="Business.Entities.Item" table="ITEM">

<id name="ITEM_ID" column="ITEM_ID" type="Int32" unsaved-value="null">
<generator class="native"/>
</id>
<set name="Bids" inverse="true" cascade="all-delete-orphan">
<key column="ITEM_ID"></key>
<one-to-many class="Bid"/>
</set>
<property column="Name" type="string" name="Name" />
<property column="Description" type="string" name="Description" />
</class>
</hibernate-mapping>

-----------------------------------------This is my child class-----------------------------------


public class Bid
{
private int _BID_ID;
private int _Amount;
private int _ITEM_ID;
private Item _itemvar;
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DTO" namespace="Business.Entities">
<class name="Business.Entities.Bid" table="BID">

<id name="BID_ID" column="BID_ID" type="Int32" unsaved-value="null">
<generator class="native"/>
</id>
<many-to-one name="itemvar" column="ITEM_ID" class="Item" not-null="false">
</many-to-one>

<property column="Amount" type="int" name="Amount" />
</class>
</hibernate-mapping>

---------------This is where i am calling my methods to save data in to child-------------------------



Bid bid = new Bid();
bid.Amount = 100;

Item item = new Item();
item.Name = "jewlry";
item.Description = "Its kool man";

item.addBid(bid);

DAL.DAL pub = new DAL.DAL();
pub.addItems(item);




public void addBids(Bid bid)
{
try
{
session.Save(bid);
session.Flush();
}
catch (Exception ex)
{
throw ex;
}
}




Can any body Tell me how to Fix this... i tried my best at net and book but didn't find ans... i can insert values in Parent.. but cant insert value in Child... its putting null there... ANY Solution will be greatly appreciated


Top
 Profile  
 
 Post subject: Re: Session.save is not Working right...
PostPosted: Mon Sep 14, 2009 2:24 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I don't quite understand your problem. Do you try to save a new bid with new items or just a new item for an existing bid ? Code looks like you try the first.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Session.save is not Working right...
PostPosted: Mon Sep 14, 2009 2:34 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 6:44 am
Posts: 24
infect i am very new to it... i have been reading books properly and did google too.. but didnt find out proper ans...

i made a parent child relation ..

and now when i save
parent object it works well.. and when i go for saving child it gave me error...
i was looking for exact peice of code which can only save child... i will do then rest of it
and it will give me clear idea that how things really work in Nhibernate...
at this stage it tough for me..indeed pretty tough..
you help will be.. greatllyyy appreicated... thanks man


Top
 Profile  
 
 Post subject: Re: Session.save is not Working right...
PostPosted: Mon Sep 14, 2009 2:42 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
What kind of error ? Post the exception and have a look at the inner exception. Here're some samples about parent-child-mappings:

http://nhforge.org/doc/nh/en/index.html#example-parentchild

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Session.save is not Working right...
PostPosted: Mon Sep 14, 2009 3:13 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 6:44 am
Posts: 24
you are my man.....
Thanks man i just read the link and i am done
it took me 4 days to figure out what to do.. and you done it in a sec :)
great man.
One last thing i am new to Nhibernate and my objective is to made an ERP in some ORM and i choose Nhibernate.
what should be the guide line to aim For ERP. should i read the book First through out ? or should i made a small application it.. and will it be very tough in future to manage associations in mapping file.
In short a guy with good aptitude towards learning what do you think how long it will take time to get expert in Nhibernate and which is the best book to learn Nhibernate......
Thansk a loooott for you time man..
may GOD give you the rewards.


Top
 Profile  
 
 Post subject: Re: Session.save is not Working right...
PostPosted: Mon Sep 14, 2009 3:25 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I suggest "NHibernate in Action" and the reference documentation (very technical but also very detailled and informative, but not easy to start with http://nhforge.org/doc/nh/en/index.html). There also is a lot of information in this site:

http://nhforge.org/

Especially the blogs. There are some major things you have to know about:

- what kind of session handling do I want to use
- lazy loading or not

You kind find a lot of infos on this at NHForge.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Session.save is not Working right...
PostPosted: Mon Sep 14, 2009 3:30 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 6:44 am
Posts: 24
Thanks man...
you made my day.
Regards,
Asfand.


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