-->
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: How to Create a Derived Collection of Objects
PostPosted: Mon Mar 31, 2008 12:13 pm 
Newbie

Joined: Tue Feb 26, 2008 1:17 pm
Posts: 9
Hi all. I am trying to create a Set of objects without having an explicit foreign key. I have tried several things, but I am not making the connection.

I have a database schema PARTY -> ORDERS -> ORDER_ITEMS -> REGISTRATIONS, with each subsequent table having a foreign key relationship back to the previous table. Now I want to create an object, I am calling it Students, that is based on the PARTY table, but does not have all the properties (I am trying to make a lightweight Party object since it has to be eagerly loaded). I want to map only REGISTRATIONS into the Student object, and remove references to ORDERS and ORDER_ITEMS. How would I go about this without the direct foreign key relationship? I.E. How do I link the REGISTRATION_ID column of the REGISTRATIONS table back to the PARTY_ID column of the PARTY_TABLE in a single mapping? Is this even possible (I have seen this issue (check 944) http://opensource.atlassian.com/projects/hibernate/browse/HHH-2086)?

K

PS...I have tried so many things. It is a one-to-many relationship, but I have been trying to play with the many-to-many features. For example, I thought my best bet would be to create a derived property in the Registrations object that held the PARTY_ID value:

Code:
<property name="partyIdKey2" type="java.lang.Long">
            <formula>
                (select p.PARTY_ID
                from PARTY p INNER JOIN ORDERS o on p.PARTY_ID = O.PARTY_ID
                    INNER JOIN ORDER_ITEM oi on o.ORDER_ID = oi.ORDER_ID
                    INNER JOIN REGISTRATION r on oi.ORDER_ITEM_ID = r.ORDER_ITEM_ID
                where r.REGISTRATION_ID = REGISTRATION_ID)
            </formula>
        </property>


and then join on this derived property:

Code:
<hibernate-mapping>
    <class name="com.thomson.ecommerce.rebar.model.Student" table="PARTY" schema="REBAR" lazy="false">
        <id name="partyId" type="java.lang.Long">
            <column name="PARTY_ID" precision="12" scale="0" />
        </id>
        <property name="partyIdKey" type="java.lang.Long" insert="false" update="false" unique="true">
            <column name="PARTY_ID" precision="12" scale="0" />
        </property>
        <set name="regs" inverse="false" lazy="false">
            <key property-ref="partyIdKey"/>
            <many-to-many property-ref="partyIdKey2" class="com.thomson.ecommerce.rebar.model.Registration" unique="true">
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>


But it was just another failure:

Code:
09:49:36,808 DEBUG [main] (org.hibernate.jdbc.AbstractBatcher:401) - select regs0_.id as id1_, regs0_.elt as elt1_, registrati1_.REGISTRATION_ID as REGISTRA1_39_0_, registrati1_.ORDER_ITEM_ID as ORDER4_39_0_,
                (select p.PARTY_ID
                from PARTY p INNER JOIN ORDERS o on p.PARTY_ID = O.PARTY_ID
                    INNER JOIN ORDER_ITEM oi on o.ORDER_ID = oi.ORDER_ID
                    INNER JOIN REGISTRATION r on oi.ORDER_ITEM_ID = r.ORDER_ITEM_ID
                where r.REGISTRATION_ID = registrati1_.REGISTRATION_ID)
             as formula0_0_ from regs regs0_ left outer join REBAR.REGISTRATION registrati1_ on regs0_.elt=registrati1_.null where regs0_.id=?
09:49:36,828 DEBUG [main] (org.hibernate.jdbc.AbstractBatcher:374) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
09:49:36,838 ERROR [main] (org.hibernate.util.JDBCExceptionReporter:78) - ORA-01747: invalid user.table.column, table.column, or column specification


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.