-->
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: How to map foreign key constraints
PostPosted: Wed Jul 25, 2012 4:34 am 
Newbie

Joined: Wed Jul 25, 2012 3:33 am
Posts: 1
Hello Frnds,

My Product table have one foreign key CategoryId . I don't know how to Map this table & how to insert CategoryId into Product Table. I am Posting my Code but It gives me runtime error.

Products.hbm.xml file

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test_NHibernate_Join_Tables" assembly="Test_NHibernate_Join_Tables"
                  >
  <class name="Test_NHibernate_Join_Tables.Products" table="tblProducts">
    <id name="ProductId" type="int">
      <generator class="native"/>
    </id>
    <property type="string" name="ProductName" >
      <column name="ProductName"></column>
    </property>
    <set name="Category" inverse="true" cascade="all" >
      <key column="CategoryId" />
      <one-to-many class="Test_NHibernate_Join_Tables.Products"/>
    </set>
  </class>

</hibernate-mapping>


Product.cs File

Code:

public class Products
    {

        public virtual int? ProductId { get; set; }
        Category _category;
        public virtual Category Category
        {
            get
            {
                return _category;
            }
            set
            {
                _category = value;
            }
        }
        public virtual string ProductName { get; set; }
    }


Error Getting

Unable to cast object of type 'Test_NHibernate_Join_Tables.Category' to type 'Iesi.Collections.ISet'.


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.