Skip to content

Commit 9645ebf

Browse files
chandre92beikov
authored andcommitted
HHH-19011 Reproducing test
(cherry picked from commit 4c381c5)
1 parent ee8b43a commit 9645ebf

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.annotations.comment;
6+
7+
8+
import jakarta.persistence.ElementCollection;
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.GeneratedValue;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.OrderColumn;
13+
import org.hibernate.annotations.Comment;
14+
import org.hibernate.boot.Metadata;
15+
import org.hibernate.boot.spi.BootstrapContext;
16+
import org.hibernate.engine.spi.SessionFactoryImplementor;
17+
import org.hibernate.integrator.spi.Integrator;
18+
import org.hibernate.mapping.PersistentClass;
19+
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
20+
import org.hibernate.testing.orm.junit.DomainModel;
21+
import org.hibernate.testing.orm.junit.JiraKey;
22+
import org.hibernate.testing.orm.junit.SessionFactory;
23+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
24+
import org.junit.jupiter.api.Test;
25+
26+
import java.util.Collection;
27+
import java.util.List;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
@JiraKey(value = "HHH-19011")
32+
@DomainModel(annotatedClasses = {CommentElementCollectionTest.MainEntity.class})
33+
@SessionFactory
34+
@BootstrapServiceRegistry(integrators = CommentElementCollectionTest.MetadataIntegrator.class)
35+
public class CommentElementCollectionTest {
36+
private static Metadata METADATA;
37+
38+
@Test
39+
public void testTableCommentsPlacement(SessionFactoryScope scope) {
40+
scope.inSession(session -> {
41+
Collection<PersistentClass> entityBindings = METADATA.getEntityBindings();
42+
assertThat( entityBindings.iterator().next().getTable().getComment() ).isEqualTo(
43+
MainEntity.EXPECTED_MAIN_ENTITY_TABLE_COMMENT );
44+
45+
Collection<org.hibernate.mapping.Collection> collectionBindings = METADATA.getCollectionBindings();
46+
assertThat( collectionBindings.iterator().next().getCollectionTable().getComment() ).isEqualTo(
47+
MainEntity.EXPECTED_ELEMENT_COLLECTION_TABLE_COMMENT );
48+
});
49+
}
50+
51+
@Entity
52+
@Comment(MainEntity.EXPECTED_MAIN_ENTITY_TABLE_COMMENT)
53+
static class MainEntity {
54+
public static final String EXPECTED_MAIN_ENTITY_TABLE_COMMENT = "Expected main entity table level comment";
55+
public static final String EXPECTED_ELEMENT_COLLECTION_TABLE_COMMENT = "Expected element collection table level comment";
56+
57+
@Id
58+
@GeneratedValue
59+
public long id;
60+
61+
@ElementCollection
62+
@OrderColumn(name = "elementOrder", nullable = false)
63+
@Comment(EXPECTED_ELEMENT_COLLECTION_TABLE_COMMENT)
64+
public List<String> embeddableValues;
65+
}
66+
67+
public static class MetadataIntegrator implements Integrator {
68+
@Override
69+
public void integrate(Metadata metadata, BootstrapContext bootstrapContext, SessionFactoryImplementor sessionFactory) {
70+
METADATA = metadata;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)