-->
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.  [ 3 posts ] 
Author Message
 Post subject: newbie: using one-to-many mapped classes
PostPosted: Fri Sep 02, 2005 10:49 am 
Hi, I'm new to NHibernate and O/R mapping world. I've been trying to learn how to use the different kinds of mappings, but I got stuck with the one-to-many.

I'm using mysql 4.1. These are my tables:

factura
PK fac_id BIGINT autoincrement
fac_fecha DATETIME

itemfactura
PK itemf_id BIGINT
itemf_producto VARCHAR(45)
FK fac_id BIGINT


Mapping Files:

Factura.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="TestNHibernate3.Factura, TestNHibernate3" table="factura">
      <id name="Id" column="fac_id" type="Int64">
         <generator class="native"></generator>
      </id>
      <property name="Fecha" column="fac_fecha" type="DateTime"></property>
      <bag name="Items" cascade="all">
         <key column="fac_id"></key>
         <one-to-many class="TestNHibernate3.ItemFactura, TestNHibernate3"></one-to-many>
      </bag>
   </class>
</hibernate-mapping>


ItemFactura.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="TestNHibernate3.ItemFactura, TestNHibernate3" table="itemfactura">
      <id name="Id" column="itemf_id" type="Int64">
         <generator class="assigned"></generator>         
      </id>
      <property name="Producto" column="itemf_producto" type="String"></property>
      <many-to-one name="Factura" class="TestNHibernate3.Factura, TestNHibernate3" column="fac_id"></many-to-one>
   </class>
</hibernate-mapping>



Classes written in C#:

Factura
[code]
using System;
using System.Collections;

namespace TestNHibernate3
{
/// <summary>
/// Descripci


Top
  
 
 Post subject: One-to-many relationships and troubleshooting NHibernate
PostPosted: Fri Sep 02, 2005 12:52 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 12:13 pm
Posts: 44
Location: Denver, CO
Be sure to check out http://nhibernate.sourceforge.net/nh-do ... /ch06.html and also turn on logging so that you can view the actual SQL queries that are being sent to the DB. Looking at the produced SQL can save hours of troubleshooting.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 1:53 pm 
Thx a lot! It really worked out by reading the link


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