PDA

View Full Version : Enforcing field value uniqueness



jporche
Jul 29th, 2009, 02:12 PM
Is possible to specify a field to be unique? Something like:

add field string -fieldName myField -unique ....

that would then create a database column with a uniqueness constraint? Otherwise I will have to go in and manually add this constraint to all the columns that need it in the db.

Also, it would be nice to be able to define multiple-column uniqueness constraints such as in MySql:

UNIQUE KEY 'userId_2' ('userId','customerId')

FYI, using Roo 1.0.0RC1 and Java 6.

Thanks!

Ben Alex
Jul 30th, 2009, 06:36 AM
If you'd like to add a feature request to Jira, we could look into providing JPA-based uniqueness constraint definition. Realistically Roo's DSL isn't trying to eliminate the requirement for coding (and therefore you can add constraint annotations by hand to your .java files without a problem and they will work), but there may be some value in having uniqueness constraint definition support in Roo given it's such a common use case. I am presently giving some thought to Spring Shell (the part of Roo we'll split out) and how to compose a single command line from multiple add-ons, so uniqueness capabilities might be an interesting goal for this.

jporche
Jul 30th, 2009, 08:38 AM
Thanks, Ben. I created the feature request in Jira.

http://jira.springframework.org/browse/ROO-173

obobo
Sep 17th, 2009, 07:14 AM
I am just evaluating ROO, but haven't used SPRING before.

We also need uniqueness constraints, and I'm wondering what you have to do to add these as annotations?

Thanks.