Skip to content

Commit

Permalink
HHH-19011 Reproducing test
Browse files Browse the repository at this point in the history
(cherry picked from commit 4c381c5)
chandre92 authored and beikov committed Jan 16, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ee8b43a commit 9645ebf
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations.comment;


import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OrderColumn;
import org.hibernate.annotations.Comment;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@JiraKey(value = "HHH-19011")
@DomainModel(annotatedClasses = {CommentElementCollectionTest.MainEntity.class})
@SessionFactory
@BootstrapServiceRegistry(integrators = CommentElementCollectionTest.MetadataIntegrator.class)
public class CommentElementCollectionTest {
private static Metadata METADATA;

@Test
public void testTableCommentsPlacement(SessionFactoryScope scope) {
scope.inSession(session -> {
Collection<PersistentClass> entityBindings = METADATA.getEntityBindings();
assertThat( entityBindings.iterator().next().getTable().getComment() ).isEqualTo(
MainEntity.EXPECTED_MAIN_ENTITY_TABLE_COMMENT );

Collection<org.hibernate.mapping.Collection> collectionBindings = METADATA.getCollectionBindings();
assertThat( collectionBindings.iterator().next().getCollectionTable().getComment() ).isEqualTo(
MainEntity.EXPECTED_ELEMENT_COLLECTION_TABLE_COMMENT );
});
}

@Entity
@Comment(MainEntity.EXPECTED_MAIN_ENTITY_TABLE_COMMENT)
static class MainEntity {
public static final String EXPECTED_MAIN_ENTITY_TABLE_COMMENT = "Expected main entity table level comment";
public static final String EXPECTED_ELEMENT_COLLECTION_TABLE_COMMENT = "Expected element collection table level comment";

@Id
@GeneratedValue
public long id;

@ElementCollection
@OrderColumn(name = "elementOrder", nullable = false)
@Comment(EXPECTED_ELEMENT_COLLECTION_TABLE_COMMENT)
public List<String> embeddableValues;
}

public static class MetadataIntegrator implements Integrator {
@Override
public void integrate(Metadata metadata, BootstrapContext bootstrapContext, SessionFactoryImplementor sessionFactory) {
METADATA = metadata;
}
}
}

0 comments on commit 9645ebf

Please sign in to comment.