-->
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: unique-key on many-to-one class attribute ?
PostPosted: Thu Nov 16, 2006 4:36 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
Hibernate version:
3.2

I have a requirement that the FundAsset entity below be unique on the Fund primary key id and Asset.ticket . I can put unique-key on fund easily but how can I put a unique-key on Asset attribute Ticket inside FundAsset? FundAsset --> Asset.ticker and FundAsset--> Fund.id would ideally both have an unique-id tag shared between them, ie, if I tried inserting a FundAsset that already had a combo of Asset.ticker and Fund.id it would throw an exception.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.wazollc.alphatheory.hibernate.bo">
   <class name="FundAssetBO"
               table="`FUNDASSET`"
               dynamic-update="false"
               dynamic-insert="false"
               select-before-update="false"
               optimistic-lock="version"
               lazy="true"
               batch-size="6"
        >
      <id name="id" type="java.lang.Long" column="`fundAssetID`">
         <generator class="native" />
      </id>

      <property name="created" column="`created`"
                        type="timestamp"
         not-null="false" length="6" />
      <property name="modified" column="`modified`"
                        type="timestamp"
         not-null="false" length="6" />
      <property name="createdUserID" column="`createdUserID`"
         type="java.lang.Long" not-null="false" />
      <property name="modifiedUserID" column="`modifiedUserID`"
         type="java.lang.Long" not-null="false" />
      <property name="currentShares" column="`currentShares`"
         type="java.lang.Double" not-null="false" />
      <property name="washRuleDate" column="`washRuleDate`"
         type="timestamp" not-null="false" length="6" />
                <property name="maxPositionSize" column="`maxPositionSize`"
                        type="java.lang.Double" not-null="false" />     
                <property name="maxPositionReason" column="`maxPositionReason`"
                        type="java.lang.String" not-null="false" />     

                <many-to-one
                        name="asset"
                        class="com.wazollc.alphatheory.hibernate.bo.AssetBO"
                        column="`assetID`"
                        cascade="all"
                        not-null="true"
                />

                <many-to-one
                        name="fund"
                        class="com.wazollc.alphatheory.hibernate.bo.FundBO"
                        column="`fundID`"
                        cascade="save-update"
                        not-null="true"
                />

                <many-to-one
                        name="status"
                        class="com.wazollc.alphatheory.hibernate.bo.StatusBO"
                        column="`statusID`"
                        cascade="save-update"
                        not-null="true"
                />

                <many-to-one
                        name="category"
                        class="com.wazollc.alphatheory.hibernate.bo.CategoryBO"
                        column="`categoryID`"
                        cascade="save-update"
                        not-null="false"
                />

                <many-to-one
                        name="annualizeReturnOptions"
                        class="com.wazollc.alphatheory.hibernate.bo.AnnualizeReturnOptionsBO"
                        column="`annualizeReturnOptionsID`"
                        cascade="save-update"
                        not-null="true"
                />

                <many-to-one
                        name="expectedReturnCalculationOptions"
                        class="com.wazollc.alphatheory.hibernate.bo.ExpectedReturnCalculationOptionsBO"
                        column="`expectedReturnCalculationOptionsID`"
                        cascade="save-update"
                        not-null="true"
                />

                <many-to-one
                        name="analysisConfidenceOptions"
                        class="com.wazollc.alphatheory.hibernate.bo.AnalysisConfidenceOptionsBO"
                        column="`analysisConfidenceOptionsID`"
                        cascade="save-update"
                        not-null="true"
                />

                <set name="fundAssetTradeHistory" table="`fundassettradehistory`" inverse="true" order-by="shares desc" cascade="all" lazy="true">
                       <key column="`fundassetID`" />
                       <one-to-many class="com.wazollc.alphatheory.hibernate.bo.FundAssetTradeHistoryBO" />
                </set>


   </class>
</hibernate-mapping>


Here's the Asset entity, which has Ticker.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.wazollc.alphatheory.hibernate.bo">
   <class name="AssetBO"
               table="`ASSET`"
               dynamic-update="false"
               dynamic-insert="false"
               select-before-update="false"
               optimistic-lock="version"
               lazy="true"
               batch-size="6"
        >
      <id name="id" type="java.lang.Long" column="`assetID`">
         <generator class="native" />
      </id>

      <property name="created" column="`created`"
                        type="timestamp"
         not-null="false" length="6" />
      <property name="modified" column="`modified`"
                        type="timestamp"
         not-null="false" length="6" />
      <property name="createdUserID" column="`createdUserID`"
         type="java.lang.Long" not-null="false" />
      <property name="modifiedUserID" column="`modifiedUserID`"
         type="java.lang.Long" not-null="false" />
      <property name="ticker" column="`ticker`" type="java.lang.String"
         not-null="false" />
      <property name="notes" column="`notes`"
                        type="java.lang.String"
                        length="2000"
         not-null="false" />
      <property name="ideaSource" column="`ideaSource`"
                        type="java.lang.String"
                        length="2000"
         not-null="false" />
      <property name="fixedAssetPrice" column="`fixedAssetPrice`"
         type="java.lang.Double" not-null="false" />
      <property name="fixedAssetBeta" column="`fixedAssetBeta`"
         type="java.lang.Double" not-null="false" />
      <property name="fixedAssetAvgDailyVol"
         column="`fixedAssetAvgDailyVol`"
                        type="java.lang.Double"
         not-null="false" />
      <property name="fixedAssetName" column="`fixedAssetName`"
         type="java.lang.String" not-null="false" />
      <property name="fixedAssetFlag" column="`fixedAssetFlag`"
         type="java.lang.Boolean" not-null="false" />

                <many-to-one
                        name="analyst"
                        column="`analystID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        cascade="save-update"
                        not-null="true"/>

                <many-to-one
                        name="associate"
                        column="`associateID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        cascade="save-update"
                        not-null="false"/>

                <many-to-one
                        name="trader"
                        column="`traderID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        cascade="save-update"
                        not-null="false"/>


                <set name="assetsScenarios" table="`assetscenario`" inverse="true" cascade="all-delete-orphan" order-by="includeScenario desc" lazy="true">
                       <key column="`assetID`" />
                       <one-to-many class="com.wazollc.alphatheory.hibernate.bo.AssetScenarioBO" />
                </set>


   </class>
</hibernate-mapping>




Any ideas?
Robert


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 1:49 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
Anyone?

Let me try and re-phrase my question perhaps more clearer: How can I combine the fk of one table - Fund - and a column of another table referenced by a fk - Asset.ticker - to create a unique key that will prevent duplicates of these two combined columns when inserting a new table row with these fk's - FundAsset ?


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.