|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.naming; |
| 6 | + |
| 7 | +import jakarta.persistence.Entity; |
| 8 | +import jakarta.persistence.Id; |
| 9 | +import jakarta.persistence.ManyToOne; |
| 10 | +import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy; |
| 11 | +import org.hibernate.boot.model.naming.Identifier; |
| 12 | +import org.hibernate.cfg.MappingSettings; |
| 13 | +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; |
| 14 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 15 | +import org.hibernate.testing.orm.junit.Jpa; |
| 16 | +import org.hibernate.testing.orm.junit.Setting; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +@Jpa(annotatedClasses = PhysicalNamingTest.TheEntity.class, |
| 20 | + integrationSettings = @Setting( |
| 21 | + name = MappingSettings.PHYSICAL_NAMING_STRATEGY, |
| 22 | + value = "org.hibernate.orm.test.naming.PhysicalNamingTest$NamingStrategy")) |
| 23 | +public class PhysicalNamingTest { |
| 24 | + |
| 25 | + public static class NamingStrategy |
| 26 | + extends CamelCaseToUnderscoresNamingStrategy { |
| 27 | + @Override |
| 28 | + protected Identifier unquotedIdentifier(Identifier name) { |
| 29 | + Identifier identifier = super.unquotedIdentifier( name ); |
| 30 | + return new Identifier( identifier.getText() + "_", |
| 31 | + identifier.isQuoted() ); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + @JiraKey("HHH-19515") |
| 37 | + @Test void test(EntityManagerFactoryScope scope) { |
| 38 | + scope.inTransaction( em -> { |
| 39 | + // make sure _ was not appended more than once |
| 40 | + em.createNativeQuery( |
| 41 | + "select its_id_, its_name_, its_friend_its_id_ from the_entity_", |
| 42 | + Object[].class ) |
| 43 | + .getResultList(); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + @Entity(name = "TheEntity") |
| 48 | + static class TheEntity { |
| 49 | + @Id long itsId; |
| 50 | + String itsName; |
| 51 | + @ManyToOne |
| 52 | + TheEntity itsFriend; |
| 53 | + } |
| 54 | +} |
0 commit comments