title: Testing unique constraint in @DataJpaTest
body: <p>I wrote this test to verify unique constraint on <code>Domain.name</code> in the database. But it doesn't work: I expect an exception to be thrown on the <code>domainRepository.saveAndFlush(domainDuplicate)</code> operation, but the test ends successfully.</p>
  
  <pre><code>@RunWith(SpringRunner::class)
  @DataJpaTest
  class DomainRepositoryTest {
  
      @Autowired
      private lateinit var util: TestEntityManager
      @Autowired
      private lateinit var domainRepository: DomainRepository
  
      @Test
      fun testNonUniqueDomainSave() {
          // Arrange
          val domain = Domain(name = "name")
          util.persist(domain)
          util.flush()
          util.clear()
  
          val domainDuplicate = domain.copy(id = 0L)
  
          // Act
          domainRepository.saveAndFlush(domainDuplicate)
          // Exception is expected
      }
  }
  </code></pre>
  
  <p>Test log (shortened):</p>
  
  <pre><code>INFO 13522 --- [           main] o.s.t.c.transaction.TransactionContext   : Began transaction (1) for test context [DefaultTestContext@8f8717b testClass = DomainRepositoryTest,...]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@65f36591]; rollback [true]
  
  Hibernate: insert into domains (name, id) values (?, ?)
  Hibernate: insert into domains (name, id) values (?, ?)
  Hibernate: insert into domains (name, id) values (?, ?)
  
  INFO 13522 --- [           main] o.s.t.c.transaction.TransactionContext   : Rolled back transaction for test: [DefaultTestContext@8f8717b testClass = DomainRepositoryTest, ...], attributes = map[[empty]]]
  </code></pre>
  
  <p>Question: How to fix this test?
  Additional question: Why 3 insert operations in log?</p>
  
  <p>Database: H2</p>