-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help with join constraints in hibernate mapping
PostPosted: Wed Apr 02, 2008 11:48 am 
Newbie

Joined: Wed Apr 02, 2008 11:35 am
Posts: 2
I am using Hibernate version: 3.1

I have an XML hibernate mapping description:

Code:
     
<hibernate-mapping>

    <class name="com.domain.MyClass" table="DATA_TABLE">

        <id name="id" type="int" unsaved-value="null" >
            <column name="PR_ID" />     
            <generator class="org.hibernate.id.Assigned"/>
        </id>
        <property name="field1"  type="string">
            <column name="PR_FIELD1" length="120"/>
        </property>
...
        <property name="field28"  type="date">
            <column name="PR_FIELD28"/>
        </property>
       
        <!-- Mapping For Image File -->
        <join table="IMAGE_TABLE" fetch="join" optional="true">             
            <key column="IMG_PRID"/>
            <property name="jpegData"  type="blob">
                <column name="IMG_DATA" />
            </property>
        </join>
       
    </class>

</hibernate-mapping>


This works fine but I want to specify a constraint because there could be multiple images and I only want a one to one relationship.

Is is possible to do something like this:
Code:
     
        <join table="IMAGE_TABLE" fetch="join" optional="true">             
            <key column="IMG_PRID"/>
            <constraint column="IMAGE_NAME" value="MyImage" />
            <property name="jpegData"  type="blob">
                <column name="IMG_DATA" />
            </property>
        </join>


My above code clearly does not work but I could not see how to translate this to a configuration that would work.

Thanks in advance,

Doug Culnane


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 6:48 am 
Newbie

Joined: Wed Apr 02, 2008 11:35 am
Posts: 2
Got the solution. Here it is for reference

Code:
   
      <join table="IMAGE_TABLE" fetch="join" optional="true">             
            <subselect>
               select IMG_PRID, IMG_DATA
              from IMAGE_TABLE
              where IMAGE_NAME = 'MyImage'
            </subselect>
            <property name="jpegData"  type="blob">
                <column name="IMG_DATA" />
            </property>
        </join>
[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.