-->
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: hbm2ddl tool to create unique constraint for mulitple column
PostPosted: Thu Apr 08, 2004 5:27 pm 
Newbie

Joined: Thu Apr 08, 2004 4:22 pm
Posts: 4
Hi All,

I've searched and searched, but haven't come across the answer to how to generate ddl script to create a multiple column unique constraint for a table.

The Goal:

to create DDL Scripts to create a database from XDoclet javadoc tags in my java code.

Tools:
XDoclet
hbm2ddl (runs via ant task, schemaexport)

Status:

So far, I've got it running perfectly except for the generation of a unique constraint over multiple fields for a table, hbm2ddl craps out
Code:
....
[schemaexport] - Mapping collection: com.[myCompany].product.pricing.beans.PricingWithScenarioResultBean.scenarioDisqualifications -> scenarioDisqualifications
[schemaexport] - Mapping collection: com.[myCompany].product.pricing.beans.PricingWithScenarioResultBean.pointAdjustments -> pointAdjustments
[schemaexport] - Mapping collection: com.[myCompany].product.pricing.beans.PricingWithScenarioResultBean.rateAdjustments -> rateAdjustments
[schemaexport] - Mapping collection: com.[myCompany].product.pricing.beans.PricingWithScenarioResultBean.marginAdjustments -> marginAdjustments
[schemaexport] - Mapping collection: com.[myCompany].product.pricing.beans.PricingWithScenarioResultBean.ceilingAdjustments -> ceilingAdjustments
[schemaexport] - Mapping collection: com.[myCompany].product.pricing.beans.PricingWithScenarioResultBean.srpAdjustments -> srpAdjustments
[schemaexport] - Mapping file: C:\eclipseWorkspace\pricingAdmin\build\com\[myCompany]\product\pricing\beans\ProductPricingRequestBean.hbm.xml
[schemaexport] - Mapping class: com.[myCompany].product.pricing.beans.ProductPricingRequestBean -> pricingRequest
[schemaexport] - Could not configure datastore from file: C:\eclipseWorkspace\pricingAdmin\build\com\[myCompany]\product\pricing\beans\ProductPricingRequestBean.hbm.xml


So, that said, how do I define a unique constraint across mulitple columns in an hbm so that hbm2ddl will generate ddl script to create an index, and, better still, how do I translate that into XDoclet tags in my javadocs?

The closest I've gotten to solving this is guessing that the <column> element's unique-key index-key attributes would create it, but the documentation is scant.

Hibernate version: 1.2
Environment: Server Win2k sp4

Thanks!


Top
 Profile  
 
 Post subject: Solution Found
PostPosted: Thu Apr 08, 2004 7:54 pm 
Newbie

Joined: Thu Apr 08, 2004 4:22 pm
Posts: 4
The way to do this is use XDoclet's @hibernate.column tag as follows:

Code:
...
*  @hibernate.property
*
*  @hibernate.column       name="requestType"
*            index="requestTypeRequestNameIndex"
*            unique-key="requestTypeRequestName"
....


and for a unique key between another column include:

Code:
...
* @hibernate.property
* @hibernate.column       name="requestType"
*            index="requestTypeRequestNameIndex"
*            unique-key="requestTypeRequestName"
*/



and the output from hbm2ddl...

Code:
[create table script]
...
frontRatioOverride SMALLINT null,
   ignoreIncomeRatios TINYINT null,
   investmentRate NUMERIC(11,3) null,
   originalLastWithdrawl2Nd VARCHAR(255) null,
   originalLastWithdrawl3Rd VARCHAR(255) null,
   overrideRatios TINYINT null,
   primary key (ID),
   [b]unique (requestName, requestType)[/b]
);


and the index
Code:
create index requestTypeRequestNameIndex on pricingRequest (requestName, requestType);

I was getting tripped up on having to use the name attribute. I was expecting hbm2ddl to infer the name from the getter's name, e.g. getRequestType().

John


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.