|
19 | 19 | import org.hibernate.boot.MetadataBuilder;
|
20 | 20 | import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
|
21 | 21 |
|
| 22 | +import org.hibernate.testing.FailureExpected; |
22 | 23 | import org.hibernate.testing.TestForIssue;
|
23 | 24 | import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
24 | 25 | import org.hibernate.test.annotations.embedded.FloatLeg.RateIndex;
|
|
29 | 30 | import static org.junit.Assert.assertEquals;
|
30 | 31 | import static org.junit.Assert.assertFalse;
|
31 | 32 | import static org.junit.Assert.assertNotNull;
|
| 33 | +import static org.junit.Assert.assertNull; |
32 | 34 | import static org.junit.Assert.assertTrue;
|
33 | 35 |
|
34 | 36 | /**
|
@@ -74,6 +76,169 @@ public void testSimple() throws Exception {
|
74 | 76 | s.close();
|
75 | 77 | }
|
76 | 78 |
|
| 79 | + @Test |
| 80 | + @TestForIssue( jiraKey = "HHH-8172" ) |
| 81 | + public void testQueryWithEmbeddedIsNull() throws Exception { |
| 82 | + Session s; |
| 83 | + Transaction tx; |
| 84 | + Person p = new Person(); |
| 85 | + Address a = new Address(); |
| 86 | + Country c = new Country(); |
| 87 | + Country bornCountry = new Country(); |
| 88 | + c.setIso2( "DM" ); |
| 89 | + c.setName( "Matt Damon Land" ); |
| 90 | + assertNull( bornCountry.getIso2() ); |
| 91 | + assertNull( bornCountry.getName() ); |
| 92 | + |
| 93 | + a.address1 = "colorado street"; |
| 94 | + a.city = "Springfield"; |
| 95 | + a.country = c; |
| 96 | + p.address = a; |
| 97 | + p.bornIn = bornCountry; |
| 98 | + p.name = "Homer"; |
| 99 | + s = openSession(); |
| 100 | + tx = s.beginTransaction(); |
| 101 | + s.persist( p ); |
| 102 | + tx.commit(); |
| 103 | + s.close(); |
| 104 | + |
| 105 | + s = openSession(); |
| 106 | + tx = s.beginTransaction(); |
| 107 | + p = (Person) s.createQuery( "from Person p where p.bornIn is null" ).uniqueResult(); |
| 108 | + assertNotNull( p ); |
| 109 | + assertNotNull( p.address ); |
| 110 | + assertEquals( "Springfield", p.address.city ); |
| 111 | + assertNotNull( p.address.country ); |
| 112 | + assertEquals( "DM", p.address.country.getIso2() ); |
| 113 | + assertNull( p.bornIn ); |
| 114 | + tx.commit(); |
| 115 | + s.close(); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + @TestForIssue( jiraKey = "HHH-8172" ) |
| 120 | + @FailureExpected( jiraKey = "HHH-8172") |
| 121 | + public void testQueryWithEmbeddedParameterAllNull() throws Exception { |
| 122 | + Session s; |
| 123 | + Transaction tx; |
| 124 | + Person p = new Person(); |
| 125 | + Address a = new Address(); |
| 126 | + Country c = new Country(); |
| 127 | + Country bornCountry = new Country(); |
| 128 | + assertNull( bornCountry.getIso2() ); |
| 129 | + assertNull( bornCountry.getName() ); |
| 130 | + |
| 131 | + a.address1 = "colorado street"; |
| 132 | + a.city = "Springfield"; |
| 133 | + a.country = c; |
| 134 | + p.address = a; |
| 135 | + p.bornIn = bornCountry; |
| 136 | + p.name = "Homer"; |
| 137 | + s = openSession(); |
| 138 | + tx = s.beginTransaction(); |
| 139 | + s.persist( p ); |
| 140 | + tx.commit(); |
| 141 | + s.close(); |
| 142 | + |
| 143 | + s = openSession(); |
| 144 | + tx = s.beginTransaction(); |
| 145 | + p = (Person) s.createQuery( "from Person p where p.bornIn = :b" ).setParameter( "b", p.bornIn ).uniqueResult(); |
| 146 | + assertNotNull( p ); |
| 147 | + assertNotNull( p.address ); |
| 148 | + assertEquals( "Springfield", p.address.city ); |
| 149 | + assertNotNull( p.address.country ); |
| 150 | + assertEquals( "DM", p.address.country.getIso2() ); |
| 151 | + assertNull( p.bornIn ); |
| 152 | + tx.commit(); |
| 153 | + s.close(); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + @TestForIssue( jiraKey = "HHH-8172" ) |
| 158 | + @FailureExpected( jiraKey = "HHH-8172") |
| 159 | + public void testQueryWithEmbeddedParameterOneNull() throws Exception { |
| 160 | + Session s; |
| 161 | + Transaction tx; |
| 162 | + Person p = new Person(); |
| 163 | + Address a = new Address(); |
| 164 | + Country c = new Country(); |
| 165 | + Country bornCountry = new Country(); |
| 166 | + c.setIso2( "DM" ); |
| 167 | + c.setName( "Matt Damon Land" ); |
| 168 | + bornCountry.setIso2( "US" ); |
| 169 | + assertNull( bornCountry.getName() ); |
| 170 | + |
| 171 | + a.address1 = "colorado street"; |
| 172 | + a.city = "Springfield"; |
| 173 | + a.country = c; |
| 174 | + p.address = a; |
| 175 | + p.bornIn = bornCountry; |
| 176 | + p.name = "Homer"; |
| 177 | + s = openSession(); |
| 178 | + tx = s.beginTransaction(); |
| 179 | + s.persist( p ); |
| 180 | + tx.commit(); |
| 181 | + s.close(); |
| 182 | + |
| 183 | + s = openSession(); |
| 184 | + tx = s.beginTransaction(); |
| 185 | + p = (Person) s.createQuery( "from Person p where p.bornIn = :b" ).setParameter( "b", p.bornIn ).uniqueResult(); |
| 186 | + assertNotNull( p ); |
| 187 | + assertNotNull( p.address ); |
| 188 | + assertEquals( "Springfield", p.address.city ); |
| 189 | + assertNotNull( p.address.country ); |
| 190 | + assertEquals( "DM", p.address.country.getIso2() ); |
| 191 | + assertEquals( "US", p.bornIn.getIso2() ); |
| 192 | + assertNull( p.bornIn.getName() ); |
| 193 | + tx.commit(); |
| 194 | + s.close(); |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + @TestForIssue( jiraKey = "HHH-8172" ) |
| 199 | + public void testQueryWithEmbeddedWithNullUsingSubAttributes() throws Exception { |
| 200 | + Session s; |
| 201 | + Transaction tx; |
| 202 | + Person p = new Person(); |
| 203 | + Address a = new Address(); |
| 204 | + Country c = new Country(); |
| 205 | + Country bornCountry = new Country(); |
| 206 | + c.setIso2( "DM" ); |
| 207 | + c.setName( "Matt Damon Land" ); |
| 208 | + bornCountry.setIso2( "US" ); |
| 209 | + assertNull( bornCountry.getName() ); |
| 210 | + |
| 211 | + a.address1 = "colorado street"; |
| 212 | + a.city = "Springfield"; |
| 213 | + a.country = c; |
| 214 | + p.address = a; |
| 215 | + p.bornIn = bornCountry; |
| 216 | + p.name = "Homer"; |
| 217 | + s = openSession(); |
| 218 | + tx = s.beginTransaction(); |
| 219 | + s.persist( p ); |
| 220 | + tx.commit(); |
| 221 | + s.close(); |
| 222 | + |
| 223 | + s = openSession(); |
| 224 | + tx = s.beginTransaction(); |
| 225 | + p = (Person) s.createQuery( "from Person p " + |
| 226 | + "where ( p.bornIn.iso2 is null or p.bornIn.iso2 = :i ) and " + |
| 227 | + "( p.bornIn.name is null or p.bornIn.name = :n )" |
| 228 | + ).setParameter( "i", p.bornIn.getIso2() ) |
| 229 | + .setParameter( "n", p.bornIn.getName() ) |
| 230 | + .uniqueResult(); |
| 231 | + assertNotNull( p ); |
| 232 | + assertNotNull( p.address ); |
| 233 | + assertEquals( "Springfield", p.address.city ); |
| 234 | + assertNotNull( p.address.country ); |
| 235 | + assertEquals( "DM", p.address.country.getIso2() ); |
| 236 | + assertEquals( "US", p.bornIn.getIso2() ); |
| 237 | + assertNull( p.bornIn.getName() ); |
| 238 | + tx.commit(); |
| 239 | + s.close(); |
| 240 | + } |
| 241 | + |
77 | 242 | @Test
|
78 | 243 | public void testCompositeId() throws Exception {
|
79 | 244 | Session s;
|
|
0 commit comments