File tree Expand file tree Collapse file tree
org/baeldung/persistence/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 189189
190190 <properties >
191191 <!-- Spring -->
192- <org .springframework.version>4.2.5 .RELEASE</org .springframework.version>
192+ <org .springframework.version>4.3.2 .RELEASE</org .springframework.version>
193193 <javassist .version>3.20.0-GA</javassist .version>
194194
195195 <!-- persistence -->
196- <hibernate .version>4.3.11 .Final</hibernate .version>
196+ <hibernate .version>5.2.2 .Final</hibernate .version>
197197 <mysql-connector-java .version>5.1.38</mysql-connector-java .version>
198- <spring-data-jpa .version>1.8 .2.RELEASE</spring-data-jpa .version>
198+ <spring-data-jpa .version>1.10 .2.RELEASE</spring-data-jpa .version>
199199 <h2 .version>1.4.192</h2 .version>
200200
201201 <!-- logging -->
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
2- <persistence version =" 2.1" xmlns =" http://xmlns.jcp.org/xml/ns/persistence" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation =" http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" >
3- <persistence-unit name =" punit" >
2+ <persistence version =" 2.1" xmlns =" http://xmlns.jcp.org/xml/ns/persistence"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" >
5+ <persistence-unit name =" punit" >
46 <class >org.baeldung.persistence.model.Foo</class >
57 <class >org.baeldung.persistence.model.Bar</class >
6- <properties >
8+ <properties >
79 <property name =" javax.persistence.jdbc.user" value =" root" />
810 <property name =" javax.persistence.jdbc.driver" value =" com.mysql.jdbc.Driver" />
911 <property name =" javax.persistence.jdbc.url" value =" jdbc:mysql://localhost:3306/HIBERTEST" />
1012 <property name =" javax.persistence.ddl-generation" value =" drop-and-create-tables" />
1113 <property name =" javax.persistence.logging.level" value =" INFO" />
12- <property name = " hibernate.show_sql" value = " true" />
13- <property name = " hibernate.cache.use_second_level_cache" value = " false" />
14- <property name = " hibernate.cache.use_query_cache" value = " false" />
14+ <property name = " hibernate.show_sql" value = " true" />
15+ <property name = " hibernate.cache.use_second_level_cache" value = " false" />
16+ <property name = " hibernate.cache.use_query_cache" value = " false" />
1517 </properties >
18+
1619 </persistence-unit >
1720</persistence >
Original file line number Diff line number Diff line change 22
33import static org .junit .Assert .assertNotNull ;
44import static org .junit .Assert .assertNull ;
5+ import static org .junit .Assert .fail ;
56
67import org .baeldung .config .ProductConfig ;
78import org .baeldung .config .UserConfig ;
@@ -57,10 +58,13 @@ public void whenCreatingUsersWithSameEmail_thenRollback() {
5758 user2 .setAge (10 );
5859 try {
5960 user2 = userRepository .save (user2 );
61+ userRepository .flush ();
62+ fail ("DataIntegrityViolationException should be thrown!" );
6063 } catch (final DataIntegrityViolationException e ) {
64+ // Expected
65+ } catch (final Exception e ) {
66+ fail ("DataIntegrityViolationException should be thrown, instead got: " + e );
6167 }
62-
63- assertNull (userRepository .findOne (user2 .getId ()));
6468 }
6569
6670 @ Test
You can’t perform that action at this time.
0 commit comments