File tree Expand file tree Collapse file tree 4 files changed +6
-112
lines changed
main/java/org/baeldung/ex/mappingexception
test/java/org/baeldung/ex/mappingexception Expand file tree Collapse file tree 4 files changed +6
-112
lines changed Original file line number Diff line number Diff line change 22
33import java .io .Serializable ;
44
5- import javax .persistence .Column ;
65import javax .persistence .GeneratedValue ;
76import javax .persistence .GenerationType ;
87import javax .persistence .Id ;
@@ -13,19 +12,10 @@ public class Foo implements Serializable {
1312 @ GeneratedValue (strategy = GenerationType .AUTO )
1413 private long id ;
1514
16- @ Column (nullable = false )
17- private String name ;
18-
1915 public Foo () {
2016 super ();
2117 }
2218
23- public Foo (final String name ) {
24- super ();
25-
26- this .name = name ;
27- }
28-
2919 // API
3020
3121 public long getId () {
@@ -36,46 +26,4 @@ public void setId(final long id) {
3626 this .id = id ;
3727 }
3828
39- public String getName () {
40- return name ;
41- }
42-
43- public void setName (final String name ) {
44- this .name = name ;
45- }
46-
47- //
48-
49- @ Override
50- public int hashCode () {
51- final int prime = 31 ;
52- int result = 1 ;
53- result = prime * result + ((name == null ) ? 0 : name .hashCode ());
54- return result ;
55- }
56-
57- @ Override
58- public boolean equals (final Object obj ) {
59- if (this == obj )
60- return true ;
61- if (obj == null )
62- return false ;
63- if (getClass () != obj .getClass ())
64- return false ;
65- final Foo other = (Foo ) obj ;
66- if (name == null ) {
67- if (other .name != null )
68- return false ;
69- } else if (!name .equals (other .name ))
70- return false ;
71- return true ;
72- }
73-
74- @ Override
75- public String toString () {
76- final StringBuilder builder = new StringBuilder ();
77- builder .append ("Foo [name=" ).append (name ).append ("]" );
78- return builder .toString ();
79- }
80-
8129}
Original file line number Diff line number Diff line change 22
33import java .io .Serializable ;
44
5- import javax .persistence .Column ;
65import javax .persistence .Entity ;
76import javax .persistence .GeneratedValue ;
87import javax .persistence .GenerationType ;
@@ -15,19 +14,10 @@ public class Foo implements Serializable {
1514 @ GeneratedValue (strategy = GenerationType .AUTO )
1615 private long id ;
1716
18- @ Column (nullable = false )
19- private String name ;
20-
2117 public Foo () {
2218 super ();
2319 }
2420
25- public Foo (final String name ) {
26- super ();
27-
28- this .name = name ;
29- }
30-
3121 // API
3222
3323 public long getId () {
@@ -38,46 +28,4 @@ public void setId(final long id) {
3828 this .id = id ;
3929 }
4030
41- public String getName () {
42- return name ;
43- }
44-
45- public void setName (final String name ) {
46- this .name = name ;
47- }
48-
49- //
50-
51- @ Override
52- public int hashCode () {
53- final int prime = 31 ;
54- int result = 1 ;
55- result = prime * result + ((name == null ) ? 0 : name .hashCode ());
56- return result ;
57- }
58-
59- @ Override
60- public boolean equals (final Object obj ) {
61- if (this == obj )
62- return true ;
63- if (obj == null )
64- return false ;
65- if (getClass () != obj .getClass ())
66- return false ;
67- final Foo other = (Foo ) obj ;
68- if (name == null ) {
69- if (other .name != null )
70- return false ;
71- } else if (!name .equals (other .name ))
72- return false ;
73- return true ;
74- }
75-
76- @ Override
77- public String toString () {
78- final StringBuilder builder = new StringBuilder ();
79- builder .append ("Foo [name=" ).append (name ).append ("]" );
80- return builder .toString ();
81- }
82-
8331}
Original file line number Diff line number Diff line change 11package org .baeldung .ex .mappingexception ;
22
3- import static org .apache .commons .lang3 .RandomStringUtils .randomAlphabetic ;
4-
53import org .baeldung .ex .mappingexception .cause1 .persistence .model .Foo ;
64import org .baeldung .ex .mappingexception .spring .Cause1PersistenceConfig ;
5+ import org .hibernate .MappingException ;
76import org .hibernate .SessionFactory ;
87import org .junit .Test ;
98import org .junit .runner .RunWith ;
@@ -22,10 +21,10 @@ public class Cause1MappingExceptionIntegrationTest {
2221
2322 // tests
2423
25- @ Test
24+ @ Test ( expected = MappingException . class )
2625 @ Transactional
2726 public final void givenEntityIsPersisted_thenException () {
28- sessionFactory .getCurrentSession ().saveOrUpdate (new Foo (randomAlphabetic ( 6 ) ));
27+ sessionFactory .getCurrentSession ().saveOrUpdate (new Foo ());
2928 }
3029
3130}
Original file line number Diff line number Diff line change 11package org .baeldung .ex .mappingexception ;
22
3- import static org .apache .commons .lang3 .RandomStringUtils .randomAlphabetic ;
4-
53import org .baeldung .ex .mappingexception .cause2 .persistence .model .Foo ;
64import org .baeldung .ex .mappingexception .spring .Cause2PersistenceConfig ;
5+ import org .hibernate .MappingException ;
76import org .hibernate .SessionFactory ;
87import org .junit .Test ;
98import org .junit .runner .RunWith ;
@@ -22,10 +21,10 @@ public class Cause2MappingExceptionIntegrationTest {
2221
2322 // tests
2423
25- @ Test
24+ @ Test ( expected = MappingException . class )
2625 @ Transactional
2726 public final void givenEntityIsPersisted_thenException () {
28- sessionFactory .getCurrentSession ().saveOrUpdate (new Foo (randomAlphabetic ( 6 ) ));
27+ sessionFactory .getCurrentSession ().saveOrUpdate (new Foo ());
2928 }
3029
3130}
You can’t perform that action at this time.
0 commit comments