-->
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: joined-subclass against the same table?
PostPosted: Fri Feb 12, 2010 1:04 am 
Newbie

Joined: Fri Feb 12, 2010 12:55 am
Posts: 1
I've got a Transaction parent class that reflects a "Transactions" table in our database. We then have child tables such as CreditCardPayments, CashPayments, CheckPayments, etc. We also have a table, "Transfers," that acts as a child class for two transactions. The Transfers table has "from_transaction_id" and "to_transaction_id" columns.

I tried to implement it as follows (with just the transfer applicable sections):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Lib" namespace="Lib.Domain">
   <class name="Lib.Domain.Transaction, Lib" table="Transactions">
      <id name="Id" column="transaction_id">
         <generator class="native" />
      </id>
      <property name="EnterDate" column="enter_date" generated="insert" />
      <property name="Amount" column="amount" />
      <property name="Type" column="transaction_type_id" />
      <property name="Status" column="transaction_status_id" />

      <many-to-one name="User" class="User" column="user_id" />
   
    <!-- Define transfers -->
    <joined-subclass name="TransferReceived" table="Transfers">
      <key column="to_transaction_id" />

      <property name="Comments" column="comments" length="500" />
      <many-to-one name="FromTransaction" class="Transaction" column="from_transaction_id" cascade="all" />
    </joined-subclass>
    <joined-subclass name="TransferSent" table="Transfers">
      <key column="from_transaction_id" />

      <property name="Comments" column="comments" length="500" />
      <many-to-one name="ToTransaction" class="Transaction" column="to_transaction_id" cascade="all" />
    </joined-subclass>
   
   </class>
</hibernate-mapping>


The issue I am running into is that the query it executes doesn't seem correct and it results in the error "Cannot instantiate abstract class or interface: Lib.Domain.Transaction." It joins on Transfers twice (as expected) on the same column (from_transaction_id -- not expected). It should join once on to_transaction_id and once on from_transaction_id. I can get it to read properly if I create a view for transfers sent and transfers received. But, of course, I then cannot persist the changes to the database. Any thoughts on if I am doing this wrong or what I need to do to get this to work?


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.