diff --git a/spring-hibernate4/pom.xml b/spring-hibernate4/pom.xml index e966579fad..254d9e1118 100644 --- a/spring-hibernate4/pom.xml +++ b/spring-hibernate4/pom.xml @@ -1,172 +1,179 @@ - - 4.0.0 - org.baeldung - spring-hibernate4 - 0.1-SNAPSHOT + + 4.0.0 + org.baeldung + spring-hibernate4 + 0.1-SNAPSHOT - spring-hibernate4 - war + spring-hibernate4 + war - + - + - - org.springframework - spring-web - ${org.springframework.version} - - - org.springframework - spring-orm - ${org.springframework.version} - - - org.springframework - spring-context - ${org.springframework.version} - + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework + spring-context + ${org.springframework.version} + - + - - org.hibernate - hibernate-core - 4.2.1.Final - - - org.javassist - javassist - 3.17.1-GA - - - mysql - mysql-connector-java - 5.1.25 - runtime - + + org.hibernate + hibernate-core + 4.2.1.Final + + + org.javassist + javassist + 3.17.1-GA + + + mysql + mysql-connector-java + 5.1.25 + runtime + - + + + + org.hibernate + hibernate-validator + 5.0.1.Final + - - com.google.guava - guava - 14.0.1 - + - + + com.google.guava + guava + 14.0.1 + - - org.apache.commons - commons-lang3 - 3.1 - test - + - - org.springframework - spring-test - ${org.springframework.version} - test - + + org.apache.commons + commons-lang3 + 3.1 + test + - - junit - junit-dep - ${junit.version} - test - + + org.springframework + spring-test + ${org.springframework.version} + test + - - org.hamcrest - hamcrest-core - ${org.hamcrest.version} - test - - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - + + junit + junit-dep + ${junit.version} + test + - - org.mockito - mockito-core - ${mockito.version} - test - + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + - + + org.mockito + mockito-core + ${mockito.version} + test + - - spring-hibernate4 - - - src/main/resources - true - - + - + + spring-hibernate4 + + + src/main/resources + true + + - - org.apache.maven.plugins - maven-surefire-plugin - - - - - - - - - + - - org.codehaus.cargo - cargo-maven2-plugin - - true - - jetty8x - embedded - - - - - - - 8082 - - - - + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + + + + - + + org.codehaus.cargo + cargo-maven2-plugin + + true + + jetty8x + embedded + + + + + + + 8082 + + + + - + - - - 3.2.2.RELEASE + - - 1.7.5 - 1.0.11 + + + 3.2.2.RELEASE - - 1.3 - 4.11 - 1.9.5 + + 1.7.5 + 1.0.11 - 4.2.4 - 4.2.4 + + 1.3 + 4.11 + 1.9.5 - 1.8.0 - 1.8.9 + 4.2.4 + 4.2.4 - + 1.8.0 + 1.8.9 + + \ No newline at end of file diff --git a/spring-hibernate4/src/main/java/org/baeldung/spring/persistence/model/Foo.java b/spring-hibernate4/src/main/java/org/baeldung/spring/persistence/model/Foo.java index 8b03df39e7..2bf8f7f008 100644 --- a/spring-hibernate4/src/main/java/org/baeldung/spring/persistence/model/Foo.java +++ b/spring-hibernate4/src/main/java/org/baeldung/spring/persistence/model/Foo.java @@ -5,6 +5,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.validation.constraints.NotNull; @Entity public class Foo { @@ -14,6 +15,7 @@ public class Foo { private long id; @Column(nullable = false) + @NotNull private String name; public Foo() { diff --git a/spring-hibernate4/src/test/java/org/baeldung/spring/persistence/service/FooServicePersistenceIntegrationTest.java b/spring-hibernate4/src/test/java/org/baeldung/spring/persistence/service/FooServicePersistenceIntegrationTest.java index fae40cdad0..3020250f6d 100644 --- a/spring-hibernate4/src/test/java/org/baeldung/spring/persistence/service/FooServicePersistenceIntegrationTest.java +++ b/spring-hibernate4/src/test/java/org/baeldung/spring/persistence/service/FooServicePersistenceIntegrationTest.java @@ -7,6 +7,8 @@ import org.baeldung.spring.persistence.model.Foo; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -30,10 +32,26 @@ public class FooServicePersistenceIntegrationTest { service.create(new Foo(randomAlphabetic(6))); } - // @Test(expected = DataIntegrityViolationException.class) - @Test + @Test(expected = DataIntegrityViolationException.class) public final void whenInvalidEntityIsCreated_thenDataException() { service.create(new Foo()); } + @Test(expected = DataIntegrityViolationException.class) + public final void whenEntityWithLongNameIsCreated_thenDataException() { + service.create(new Foo(randomAlphabetic(2048))); + } + + @Test(expected = InvalidDataAccessApiUsageException.class) + public final void whenSameEntityIsCreatedTwice_thenDataException() { + final Foo entity = new Foo(randomAlphabetic(8)); + service.create(entity); + service.create(entity); + } + + @Test + public final void temp_whenInvalidEntityIsCreated_thenDataException() { + service.create(new Foo(randomAlphabetic(2048))); + } + }