-->
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: correct mapping for given table structure
PostPosted: Wed May 30, 2007 1:03 am 
Newbie

Joined: Fri Oct 13, 2006 10:11 am
Posts: 3
Hi there!

I have to work on a given table structure and use NHibernate with mapping attributes. I'm trying to create a mapping for a one-to-one relation.

The table situation is like that:
parent table's columns:
Code:
  id          (guid)
  is_deleted  (boolean)
  {some more values}

childA table's columns: (having a one-to-one relation to the parent)
Code:
  id          (guid)
  parent_id   (guid)
  {some values}

childB table's columns: (having an ordered many-to-one relation to the parent)
Code:
  id          (guid)
  parent_id   (guid)
  order       (int)
  {some values}

I know/read that the one-to-one relation could even be created as a many-to-one, but nevertheless I'm stuck with the attributes/the mapping on that one with the given table structure.

Hibernate version: 1.2.0.2002
Mapping attributes: that's the question
Code:
[Serializable]
[Class(Table = "parent", Lazy = false)]
public class ParentClass
{
  #region --- private ---
  private Guid m_Id;
  private bool m_IsDeleted;
  private IList<ChildBClass> m_ChildBList;
  private ChildAClass m_ChildA;
  #endregion --- private ---

  public ParentClass()
  {
    m_Id = Guid.Empty;
    m_IsDeleted = false;
    m_ChildBList = new List<ChildBClass>();
    m_ChildA = new ChildAClass();
  }

  [Id(0, Name = "Id", Column = "id", Type = "Guid")]
  [Generator(1, Class = "guid")]
  public virtual Guid Id
  {
    get { return (m_Id); }
    set { m_Id = value; }
  }

  [Property(Column = "is_deleted", Type = "Boolean")]
  public virtual bool IsDeleted
  {
    get { return (m_IsDeleted); }
    set { m_IsDeleted = value; }
  }

  [List(0, Table = "childB", Lazy = false, Cascade = CascadeStyle.AllDeleteOrphan)]
  [Key(1, Column = "parent_id")]
  [Index(2, Column = "order", Type = "Int32")]
  [OneToMany(3, Class = "ChildBClass, hbm_assembly")]
  public virtual IList<ChildBClass> ChildBList
  {
    get { return (m_ChildBList); }
    set { m_ChildB = value; }
  }

  [OneToOne(Class = "ChildAClass, hbm_assembly", ???????]
  public virtual ChildAClass ChildA
  {
    get { return (m_ChildA); }
    set { m_ChildA = value; }
  }
}

[b]Any help highly appreciated![\b]


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.