|
| 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.secondarytable; |
| 6 | + |
| 7 | +import jakarta.persistence.Column; |
| 8 | +import jakarta.persistence.Entity; |
| 9 | +import jakarta.persistence.Id; |
| 10 | +import jakarta.persistence.PrimaryKeyJoinColumn; |
| 11 | +import jakarta.persistence.SecondaryTable; |
| 12 | +import org.hibernate.annotations.SecondaryRow; |
| 13 | +import org.hibernate.boot.model.naming.Identifier; |
| 14 | +import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; |
| 15 | +import org.hibernate.cfg.AvailableSettings; |
| 16 | +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; |
| 17 | +import org.hibernate.persister.entity.EntityPersister; |
| 18 | +import org.hibernate.persister.entity.mutation.EntityTableMapping; |
| 19 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 20 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 21 | +import org.hibernate.testing.orm.junit.ServiceRegistry; |
| 22 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 23 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 24 | +import org.hibernate.testing.orm.junit.Setting; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 28 | + |
| 29 | +@ServiceRegistry( |
| 30 | + settings = { |
| 31 | + @Setting(name = AvailableSettings.PHYSICAL_NAMING_STRATEGY, value = "org.hibernate.orm.test.annotations.secondarytable.SecondaryTableQuotingTest$TestNamingStrategy") |
| 32 | + } |
| 33 | +) |
| 34 | +@DomainModel(annotatedClasses = SecondaryTableQuotingTest.Foo.class) |
| 35 | +@SessionFactory |
| 36 | +@JiraKey(value = "HHH-6328") |
| 37 | +public class SecondaryTableQuotingTest { |
| 38 | + |
| 39 | + @Test |
| 40 | + public void test(SessionFactoryScope scope) { |
| 41 | + final EntityPersister entityDescriptor = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel() |
| 42 | + .getEntityDescriptor( Foo.class ); |
| 43 | + final EntityTableMapping secondaryTableMapping = entityDescriptor.getTableMappings()[1]; |
| 44 | + assertFalse( secondaryTableMapping.isOptional() ); |
| 45 | + } |
| 46 | + |
| 47 | + @Entity(name = "Foo") |
| 48 | + @SecondaryTable(name = "bar", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "foo_id")}) |
| 49 | + @SecondaryRow(table = "bar", optional = false) |
| 50 | + public static class Foo { |
| 51 | + @Id |
| 52 | + private Long id; |
| 53 | + private String name; |
| 54 | + @Column(name = "bar_value", table = "bar") |
| 55 | + private Long barValue; |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | + public static class TestNamingStrategy extends PhysicalNamingStrategyStandardImpl { |
| 60 | + @Override |
| 61 | + public Identifier toPhysicalTableName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) { |
| 62 | + return Identifier.toIdentifier( "TAB_" + logicalName.getText() ); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments