1

I have below classes. How can I write mapping document for MainBranch.Id column. I have no branch table in database, just want to use branchId for MAINBRANCHCODE. Any Idea?

public class Bundle
        {
            public virtual Decimal Id { get; set; }       
            public virtual BundleEntranceInformation Information { get; set; } 
        }
    public class BundleEntranceInformation
        {
            public virtual Branch MainBranch { get; set; }      
        }
    public class Branch
        {
            public virtual short Id { get; set; }       
        }

My mapping document:

<class name="PromissoryNotes.Server.Data.Bundle, PromissoryNotes.Server.Data" table="BUNDLE" lazy="true">
    <id name="Id" column="ID" type="Decimal">
      <generator class="increment" />
    </id>   
    <property name="Information.MainBranch.Id" column="MAINBRANCHCODE" type="short"></property>

  </class>

3 Answers 3

2

Use a component mapping

<class name="BundleEntranceInformation">
  <component name="MainBranch">
    <property name="Id" column="MAINBRANCHCODE"/>
  </component>
</class>
Sign up to request clarification or add additional context in comments.

1 Comment

yes you are right, I found it, I need to use component but not like this. Thanks for idea. Answer is as below :)
1

Here is the answer :)

<component name="Information">
   <component name="MainBranch">
     <property name="Id" column="MAINBRANCHCODE"/>
   </component>
</component  >

Comments

1
public class MainClass
{
  public virtual long MainKey {get; set;}
  public virtual SubClass SubInstance {get; set;}

  public class SubClass
  {
    public virtual long SubKey {get;set;}
  }
}

can be mapped as:

<class name="MainClass" table="Main">
  <id name="MainKey" column="MainId" type="Int64">
    <generator class="identity" />
  </id>
  <many-to-one name="SubInstance" class="MainClass+SubClass" Column="SubId"/> 
</class>

<class name="MainClass+SubClass" table="Sub">
  <id name="SubKey" column="SubId" type="Int64">
    <generator class="identity" />
  </id>
</class>

So the plus sign is key (I believe that java-hibernate uses the dollar sign $ for this)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.