-->
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: one-to-one und one-to-may Problem
PostPosted: Tue Mar 25, 2008 12:06 pm 
Newbie

Joined: Tue Mar 25, 2008 11:48 am
Posts: 12
Ola!

Ich habe ein Problem mit One2one und One2Many. Da ich die .hbm erzeugen lasse, erstmal der Aufbau der cs Datei:

Code:
    [NHibernate.Mapping.Attributes.Class(Table = "AdressBuch")]
    public partial class AdressBuch
    {

        private int _id = 0;

        private AdressBuchAdresse[] _adresse;

        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return this._id;
            }
        }

        [NHibernate.Mapping.Attributes.Array(0, Cascade = NHibernate.Mapping.Attributes.CascadeStyle.All, Name = "Adresse")] //,Lazy = true)]
        [NHibernate.Mapping.Attributes.Key(1, Column = "Id_key")] // Aktueller Index des Vaters
        [NHibernate.Mapping.Attributes.Index(2,Column = "Id_Index", Type = "int" )] //Index innerhalb der Liste
        [NHibernate.Mapping.Attributes.OneToMany(3,ClassType = typeof(abc.AdressBuchAdresse))]
        public AdressBuchAdresse[] Adresse
        {
            get
            {
                return this._adresse;
            }
            set
            {
                this._adresse = value;
            }
        }
    }

    [NHibernate.Mapping.Attributes.Class(Table = "AdressBuchAdresse")]
    public partial class AdressBuchAdresse
    {

        private int _id = 0;

        private AdressBuchAdresseName _name;

        private string _vorname;

        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return this._id;
            }
        }
       
        // Hier ist genau das Problem
        public AdressBuchAdresseName Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property()]
        public string Vorname
        {
            get
            {
                return this._vorname;
            }
            set
            {
                this._vorname = value;
            }
        }

    [NHibernate.Mapping.Attributes.Class(Table = "AdressBuchAdresseName")]
    public partial class AdressBuchAdresseName
    {

        private int _id = 0;

        private bool _important;

        private string _value;

        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return this._id;
            }
        }

        [NHibernate.Mapping.Attributes.Property()]
        public bool Important
        {
            get
            {
                return this._important;
            }
            set
            {
                this._important = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property()]
        public string Value
        {
            get
            {
                return this._value;
            }
            set
            {
                this._value = value;
            }
        }
    }
}


Mit Hilfe das .hbm und der daraus generierten .sql Datei, wird das Modell auch (fast richtig) in der Datenbank abgebildet. Daraus ensteht folgendes Schema:

Code:
create table AdressBuchAdresseName (
  Id INT IDENTITY NOT NULL,
   Important BIT null,
   Value NVARCHAR(255) null,
   primary key (Id)
)
create table AdressBuch (
  Id INT IDENTITY NOT NULL,
   primary key (Id)
)
create table AdressBuchAdresse (
  Id INT IDENTITY NOT NULL,
   Vorname NVARCHAR(255) null,
   Id_key INT null,
   Id_Index INT null,
   primary key (Id)
)
alter table AdressBuchAdresse  add constraint FK_01 foreign key (Id_key) references AdressBuch


Jetzt kommen wir zum Problem: Ich würde aus dem Queltext heraus jetzt auch gerne ein Constraint generieren, das die beiden Tabellen AdressBuchAdresse und AdressBuchAdresseName miteinander verbindet. Da die Property Name in der Klasse AdressBuchAdresse aber kein Array ist, kann ich das auf die bekannte Art nicht machen. Mit der One-to-One Möglichkeit, die mir von NHibernate angeboten wird, habe ich es leider nicht geschafft.

Deshalb die Frage und Bitte an Euch: Wie kann ich das machen?!?

Falls noch Sachen oder Informationen fehlen, bitte melden...und schon mal vielen Dank für die Hilfe,

Gruß

teLLy[/code]


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.