4 Replies Latest reply on Aug 20, 2004 5:18 AM by Tomer ben david

    unique constraint & TransactionRolledbackLocalException timi

    Tomer ben david Novice

      Hi

      I have a unique constraint on an alias field (I dont want two users with the same alias) on a mysql database in this way :

      ALTER TABLE User ADD UNIQUE(alias);
      


      I have a test client like this (pseudo code)

      public void setUp() {
       // Set up user1 entity with alias1
       // Set up user2 entity with alias2
      }
      
      public void testUnique() {
       try {
       // Try and make user2 have the same alias as user2
       sessionFacade.setAlias(user2, user1.getAlias());
       } catch (TransactionRolledbackLocalException e) {
       // Everything is fine we dont allow duplicity.
       }
      }
      
      public void tearDown() {
       try {
       someOtherEntity.remove()
       } catch (TransactionRolledbackLocalException e) {
       // Why did I catch the exception only here? why not at the testUnique?
       }
      }
      


      My problem is that no exception was catched at the testUnique() method However I did catch that exception (with a description of wrong uniqueuness in alias) only at the tearDown() !!! Is that the behaviour that should be ? looks very wired to me

      PS

      my transaction is "required"