Skip to content

Commit 24dd943

Browse files
mbelladebeikov
authored andcommitted
HHH-18259 Add test for issue
1 parent d53c9aa commit 24dd943

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/delegate/MutationDelegateJoinedInheritanceTest.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.testing.jdbc.SQLStatementInspector;
2222
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
2323
import org.hibernate.testing.orm.junit.DomainModel;
24+
import org.hibernate.testing.orm.junit.Jira;
2425
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
2526
import org.hibernate.testing.orm.junit.SessionFactory;
2627
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@@ -42,10 +43,12 @@
4243
*
4344
* @author Marco Belladelli
4445
*/
45-
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
46+
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class )
4647
@DomainModel( annotatedClasses = {
4748
MutationDelegateJoinedInheritanceTest.BaseEntity.class,
4849
MutationDelegateJoinedInheritanceTest.ChildEntity.class,
50+
MutationDelegateJoinedInheritanceTest.NonGeneratedParent.class,
51+
MutationDelegateJoinedInheritanceTest.GeneratedChild.class,
4952
} )
5053
@SessionFactory( useCollectingStatementInspector = true )
5154
public class MutationDelegateJoinedInheritanceTest {
@@ -181,6 +184,35 @@ public void testUpdateChildEntity(SessionFactoryScope scope) {
181184
} );
182185
}
183186

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+
184216
private static GeneratedValuesMutationDelegate getDelegate(
185217
SessionFactoryScope scope,
186218
@SuppressWarnings( "SameParameterValue" ) Class<?> entityClass,
@@ -244,4 +276,32 @@ public Date getChildUpdateDate() {
244276
return childUpdateDate;
245277
}
246278
}
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+
}
247307
}

0 commit comments

Comments
 (0)