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: Need help with Nhibernate.Mapping.Attribute
PostPosted: Fri Feb 08, 2008 4:50 pm 
Newbie

Joined: Sat Jul 01, 2006 3:37 pm
Posts: 7
Is there someone who knows where to find good examples
of mapping attribute.

How to une the inheritance, etc.

Thank you


Top
 Profile  
 
 Post subject: inheritance attributes example
PostPosted: Fri Feb 08, 2008 8:19 pm 
Newbie

Joined: Tue Feb 05, 2008 8:20 pm
Posts: 5
I did this:

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace AplicacionPrueba.PruebaAtrubutes
{

   
    public interface IManufacturer
    {
        string Name { get; set; }
       
    }

    [NHibernate.Mapping.Attributes.Component(ClassType=typeof(IIDEA.EALIB.AplicacionPrueba.PruebaAtrubutes.Manufacturer) )]
    public class Manufacturer : IManufacturer
    {
        private string name;
        [NHibernate.Mapping.Attributes.Property( Column = "manufacturername")]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

    public interface IVehicle
    {
        int VehicleId { get; set; }
        IManufacturer ManufacturerName { get; set; }
        string OwnerName { get; set; }
        decimal Weigth { get; set; }
    }
    [NHibernate.Mapping.Attributes.Class(Table = "vehicles")]
    public abstract class Vehicle : IVehicle
    {
        private int vehicleId;
        private IManufacturer manufacturerName;
        private string person;
        private decimal weigth;

        [NHibernate.Mapping.Attributes.Id(0, Name = "VehicleId", Column = "vehicleId", TypeType = typeof(Int32))]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "identity")]       
        public int VehicleId
        {
            get { return vehicleId; }
            set { vehicleId = value; }
        }
        [NHibernate.Mapping.Attributes.ComponentProperty(ComponentType = typeof(IIDEA.EALIB.AplicacionPrueba.PruebaAtrubutes.Manufacturer))]
        public IManufacturer ManufacturerName
        {
            get { return manufacturerName; }
            set { manufacturerName = value; }
        }
       
        [NHibernate.Mapping.Attributes.Property(Name="OwnerName", Column= "ownername")]
        public string OwnerName
        {
            get { return person; }
            set { person = value; }
        }
         
        [NHibernate.Mapping.Attributes.Property(Name="Weigth", Column= "weigth")]
        public decimal Weigth
        {
            get { return weigth; }
            set { weigth = value; }
        }
    }

    public interface IBicycle : IVehicle
    {
        string WheelSize { get; set; }
    }


    [NHibernate.Mapping.Attributes.JoinedSubclass(ExtendsType = typeof(Vehicle),  Table = "bicycles")]
    public class Bicycle : Vehicle, IBicycle
    {
       
        private string wheelSize;
        [NHibernate.Mapping.Attributes.Key(0,Column="VehicleId")]
        [NHibernate.Mapping.Attributes.Property(1,Name="WheelSize",Column="wheelsize")]
        public string WheelSize
        {
            get { return wheelSize; }
            set { wheelSize = value; }
        }
    }

    public interface IAutomotive : IVehicle
    {
        int CylinderCount { get;set;}
        int SeatCount { get;set;}
        string Description { get;set;}
    }

    [NHibernate.Mapping.Attributes.JoinedSubclass(ExtendsType = typeof(Vehicle),  Table = "automotives")]
    public class Automotive : Vehicle, IAutomotive
    {
        private int cylinderCount;
        private int seatCount;
        private string description;

        [NHibernate.Mapping.Attributes.Key(0, Column = "VehicleId")]
        [NHibernate.Mapping.Attributes.Property(1,Name="CylinderCount",Column="cylinderCount")]
        public int CylinderCount
        {
            get { return cylinderCount; }
            set { cylinderCount = value; }
        }
        [NHibernate.Mapping.Attributes.Property(Name="SeatCount",Column="seatCount")]
        public int SeatCount
        {
            get { return seatCount; }
            set { seatCount = value; }
        }
         [NHibernate.Mapping.Attributes.Property(Name="Description",Column="description")]
        public string Description
        {
            get { return description; }
            set { description = value; }
        }   

    }
}


To generate this map:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                            namespace="Northwind.Domain.Entities" assembly="Northwind.Domain">
  <class name="Vehicle" table="vehicles">
    <id name="VehicleId" type="Int32" column="vehicleId">
     
      <generator class="identity"/>
    </id>
    <property name="OwnerName" column="ownername"/>
    <property name="Weigth" column="weigth"/>

    <component name ="Manufacturer" class="Manufacturer">
      <property name="Name" column="manufacturername"/>
    </component>
   
    <!--Definición de una bicicleta.-->
    <joined-subclass name="Bicycle" table="bicycles">
      <key column="VehicleId"/>
      <property name="WheelSize" column="wheelsize"/>
    </joined-subclass>
   
    <!--Definición de un Aotomóvil-->
    <joined-subclass name="Automotive" table="automotives">
      <key column="VehicleId"/>
      <property name="CylinderCount" column="cylinderCount"/>
      <property name="SeatCount" column="seatCount"/>
      <property name="Description" column="description"/>
    </joined-subclass>
  </class>
 
 
  <sql-query name="ObtenerVehiculos">
    <return alias="listaTodosVehiculos" class="Vehicle"/>
    SELECT * FROM vehicles
  </sql-query>
  </hibernate-mapping>


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.