-->
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 map a bag (with foreign keys)
PostPosted: Fri Nov 19, 2010 10:35 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
Hi,

I am facing quite interresting scenario, I think...

I want to have a one-to-many relationship for my bag. But I want to use a two-column foreing key referencing two columns that are NOT PK. The bag is inverse because child elements get inserted separately from their parent and the association is ment for querying only - to get parent (Telegram) with its accompanying elements (Acknowledgement(s))

My solution consists from tables:
Code:
TELEGRAM
  ID PK
  TASK_ID
  CHANNEL


Code:
ACK
  ID PK
  TASK_ID
  CHANNEL


and mapping that looks somehow like

Code:
  <class name="Telegram">
    <id name="ID" column="`ID`">
      <generator class="native" />
    </id>
    <property name="TaskId" column="`TASK_ID`" not-null="false" update="false" />
    <property name="Channel" column="`CHANNEL`" update="false" />
    <bag name="AcknowledgementList" generic="true" inverse="true">
        <key foreign-key="TaskId" property-ref="TaskId">
            <column name="`TASK_ID`" />
        </key>
        <one-to-many class="Acknowledgement" />
    </bag>
  </class>


NOTE: for now I have a single column. Need two - additionally Channel column.

and mapped classes:
Code:
  <class name="Acknowledgement" table="`TTL_ACK`">
    <id name="ID" column="`ID`">
      <generator class="native" />
    </id>
    <property name="TaskId" column="`TASK_ID`" not-null="true" update="false" />
    <property name="Channel" column="`CHANNEL`" not-null="false" update="false" />
  </class>


REMARK: Maybe there's a way to prevent persisting a bag during Telegram updates - this also would solve my problems which are related to existing of shared references (of acknowledgments) among several telegrams - due to invalid select...

I know that it is not much pretty but I have quite complex environment I have to operate with...

Most things have been cut from entities for clearance purpose.

TIA

_________________
Please rate this post if you've found it helpfull
Roland


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.