Results 1 to 4 of 4

Thread: Unique key constraint for 2 fields

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    Default Unique key constraint for 2 fields

    Hi,

    In Spring Roo is there a way to add a unique key constraint on an entity for 2 fields?

    My Inventory entity has the following fields:

    Code:
    public class Inventory {
    
        private int quantityOnHand;
    
        @ManyToOne
        private Warehouse warehouse;
    
        @NotNull
        private String sku;
    }
    How do I add a constraint that sku and warehouse make a unique constraint?

  2. #2
    Join Date
    Mar 2007
    Posts
    561

    Default

    Just annotate Inventory with @UniqueConstraint

    http://docs.oracle.com/javaee/6/api/...onstraint.html

  3. #3
    Join Date
    Jul 2012
    Posts
    2

    Default

    Thank you! I can't believe I couldn't find that.

    Is there a way to define that in the roo command line or is the only way to modify the entity directly?

  4. #4
    Join Date
    Mar 2007
    Posts
    561

    Default

    You could write an addon or extend the existing one

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •