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