tags:

views:

48

answers:

2

Hi,

we use an external Database where we cant edit table designs only add own tables to extend the core tables.

So I need map two tables on one class, i try this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="DaVinci"
               namespace="DaVinci.Domain">
<class name="Vorgang" table="VORGANGSKOPF">
<id name="Id" column="ID">
<generator class="native" />
</id>
<property name="Vorgangsnummer" column="VORGANG" />
...
<join table="OWN_VORGANG_WAEHRUNG" optional="true">
      <key column="VOR_ID" property-ref="Vorgangsnummer" />
      <property name="WaehrungVK_Internet" column="WAEHRUNG" />
      <property name="WaehrungsKursVK_Internet" column="KURS" />
      <property name="Preis_Internet" column="BETRAG_EURO" />
      <property name="PreisFremdWaehrung_Internet" column="BETRAG_FREMD" />
  </join>
...

After testing i know now that "property-ref" for joins dosn't work. Bugreport here

Does anyone know an other way to map two tables on one class?

A: 

I have the same problem. I climb all over internet, but found only way to join one column from other table to current table - http://ayende.com/Blog/archive/2006/12/26/LocalizingNHibernateContextualParameters.aspx. Also I have some idea to join two tables using fetch="join" attribute (stackoverflow.com/questions/1543382/fetchjoin-to-tables-to-one-class-nhibernate), but I fail with it. Please anyone reply to this post!

Kate
A: 

(I'm struggling a little with the table and column names here.)

Could you use a joined subclass for this? Even if the tables don't follow the logical relationship, if there's a 1-to-1 database relationship between the two tables, then you'd get what you want by ignoring the parent, and doing all your operations on the subclass.

Jon Seigel