|
21 | 21 | import org.hibernate.testing.jdbc.SQLStatementInspector; |
22 | 22 | import org.hibernate.testing.orm.junit.DialectFeatureChecks; |
23 | 23 | import org.hibernate.testing.orm.junit.DomainModel; |
| 24 | +import org.hibernate.testing.orm.junit.Jira; |
24 | 25 | import org.hibernate.testing.orm.junit.RequiresDialectFeature; |
25 | 26 | import org.hibernate.testing.orm.junit.SessionFactory; |
26 | 27 | import org.hibernate.testing.orm.junit.SessionFactoryScope; |
|
42 | 43 | * |
43 | 44 | * @author Marco Belladelli |
44 | 45 | */ |
45 | | -@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class) |
| 46 | +@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class ) |
46 | 47 | @DomainModel( annotatedClasses = { |
47 | 48 | MutationDelegateJoinedInheritanceTest.BaseEntity.class, |
48 | 49 | MutationDelegateJoinedInheritanceTest.ChildEntity.class, |
| 50 | + MutationDelegateJoinedInheritanceTest.NonGeneratedParent.class, |
| 51 | + MutationDelegateJoinedInheritanceTest.GeneratedChild.class, |
49 | 52 | } ) |
50 | 53 | @SessionFactory( useCollectingStatementInspector = true ) |
51 | 54 | public class MutationDelegateJoinedInheritanceTest { |
@@ -181,6 +184,35 @@ public void testUpdateChildEntity(SessionFactoryScope scope) { |
181 | 184 | } ); |
182 | 185 | } |
183 | 186 |
|
| 187 | + @Test |
| 188 | + @Jira( "https://hibernate.atlassian.net/browse/HHH-18259" ) |
| 189 | + public void testGeneratedOnlyOnChild(SessionFactoryScope scope) { |
| 190 | + final GeneratedValuesMutationDelegate delegate = getDelegate( |
| 191 | + scope, |
| 192 | + NonGeneratedParent.class, |
| 193 | + MutationType.UPDATE |
| 194 | + ); |
| 195 | + // Mutation delegates only support generated values on the "root" table |
| 196 | + assertThat( delegate ).isNull(); |
| 197 | + |
| 198 | + final SQLStatementInspector inspector = scope.getCollectingStatementInspector(); |
| 199 | + inspector.clear(); |
| 200 | + |
| 201 | + scope.inTransaction( session -> { |
| 202 | + final GeneratedChild generatedChild = new GeneratedChild(); |
| 203 | + generatedChild.setId( 1L ); |
| 204 | + session.persist( generatedChild ); |
| 205 | + |
| 206 | + session.flush(); |
| 207 | + |
| 208 | + assertThat( generatedChild.getName() ).isEqualTo( "child_name" ); |
| 209 | + inspector.assertExecutedCount( 3 ); |
| 210 | + inspector.assertIsInsert( 0 ); |
| 211 | + inspector.assertIsInsert( 1 ); |
| 212 | + inspector.assertIsSelect( 2 ); |
| 213 | + } ); |
| 214 | + } |
| 215 | + |
184 | 216 | private static GeneratedValuesMutationDelegate getDelegate( |
185 | 217 | SessionFactoryScope scope, |
186 | 218 | @SuppressWarnings( "SameParameterValue" ) Class<?> entityClass, |
@@ -244,4 +276,32 @@ public Date getChildUpdateDate() { |
244 | 276 | return childUpdateDate; |
245 | 277 | } |
246 | 278 | } |
| 279 | + |
| 280 | + @Entity( name = "NonGeneratedParent" ) |
| 281 | + @Inheritance( strategy = InheritanceType.JOINED ) |
| 282 | + @SuppressWarnings( "unused" ) |
| 283 | + public static class NonGeneratedParent { |
| 284 | + @Id |
| 285 | + private Long id; |
| 286 | + |
| 287 | + public Long getId() { |
| 288 | + return id; |
| 289 | + } |
| 290 | + |
| 291 | + public void setId(Long id) { |
| 292 | + this.id = id; |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + @Entity( name = "GeneratedChild" ) |
| 297 | + @SuppressWarnings( "unused" ) |
| 298 | + public static class GeneratedChild extends NonGeneratedParent { |
| 299 | + @Generated( event = EventType.INSERT ) |
| 300 | + @ColumnDefault( "'child_name'" ) |
| 301 | + private String name; |
| 302 | + |
| 303 | + public String getName() { |
| 304 | + return name; |
| 305 | + } |
| 306 | + } |
247 | 307 | } |
0 commit comments