diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index 3c0af66c2580..5e9b280e2ca6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -764,7 +764,7 @@ private EmbeddableDiscriminatorMapping generateDiscriminatorMapping( return new ExplicitColumnDiscriminatorMappingImpl( this, name, - bootDescriptor.getTable().getName(), + bootDescriptor.getTable().getQualifiedName( creationContext.getSqlStringGenerationContext() ), discriminatorColumnExpression, isFormula, !isFormula, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Author.java b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Author.java new file mode 100644 index 000000000000..a42591cad3e7 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Author.java @@ -0,0 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.columndiscriminator; + +import java.util.*; + +public class Author { + private Long id; + private String name; + private String email; + private List books = new ArrayList<>(); + + public Author(String name, String email) { + this.name = name; + this.email = email; + } + + protected Author() { + // default + } + + public Long id() { + return id; + } + + public String name() { + return name; + } + + public String email() { + return email; + } + + public List books() { + return books; + } + + public void addBook(Book book) { + books.add(book); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Book.java b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Book.java new file mode 100644 index 000000000000..ca16510368e3 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Book.java @@ -0,0 +1,34 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.columndiscriminator; + +public class Book { + private Long id; + private String title; + private BookDetails details; + + public Book(String title, BookDetails details) { + this.title = title; + this.details = details; + } + + protected Book() { + // default + } + + public Long id() { + return id; + } + + public String title() { + return title; + } + + public BookDetails details() { + return details; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BookDetails.java b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BookDetails.java new file mode 100644 index 000000000000..77f8b389c71f --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BookDetails.java @@ -0,0 +1,23 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.columndiscriminator; + +public abstract class BookDetails { + private String information; + + protected BookDetails(String information) { + this.information = information; + } + + protected BookDetails() { + // default + } + + public String information() { + return information; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BoringBookDetails.java b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BoringBookDetails.java new file mode 100644 index 000000000000..235dba94696b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BoringBookDetails.java @@ -0,0 +1,24 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.columndiscriminator; + +public class BoringBookDetails extends BookDetails { + private String boringInformation; + + public BoringBookDetails(String information, String boringInformation) { + super(information); + this.boringInformation = boringInformation; + } + + public BoringBookDetails() { + // default + } + + public String boringInformation() { + return boringInformation; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/ColumnDiscrimnatorWithSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/ColumnDiscrimnatorWithSchemaTest.java new file mode 100644 index 000000000000..d8f2d3384c2b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/ColumnDiscrimnatorWithSchemaTest.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.columndiscriminator; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.SchemaToolingSettings; +import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportSchemaCreation; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + +@DomainModel(xmlMappings = "org/hibernate/orm/test/columndiscriminator/orm.xml") +@ServiceRegistry(settings = { + @Setting(name = AvailableSettings.DEFAULT_SCHEMA, value = "GREET"), + @Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS, value = "true") +}) +@SessionFactory +@RequiresDialectFeature(feature = SupportSchemaCreation.class) +class ColumnDiscrimnatorWithSchemaTest { + + private ColumnDiscrimnatorWithSchemaTest() { + } + + static ColumnDiscrimnatorWithSchemaTest createColumnDiscrimnatorWithSchemaTest() { + return new ColumnDiscrimnatorWithSchemaTest(); + } + + @Test + void testIt(SessionFactoryScope scope) { + scope.inTransaction( entityManager -> { + var book = new Book( "The Art of Computer Programming", + new SpecialBookDetails( "Hardcover", "Computer Science" ) ); + + var author = new Author( "Donald Knuth", "dn@cs.com" ); + author.addBook( book ); + entityManager.persist( author ); + } ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/SpecialBookDetails.java b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/SpecialBookDetails.java new file mode 100644 index 000000000000..5cc837e63ebf --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/SpecialBookDetails.java @@ -0,0 +1,24 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.columndiscriminator; + +public class SpecialBookDetails extends BookDetails { + private String specialInformation; + + public SpecialBookDetails(String information, String specialInformation) { + super(information); + this.specialInformation = specialInformation; + } + + protected SpecialBookDetails() { + // default + } + + public String specialInformation() { + return specialInformation; + } +} diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/columndiscriminator/orm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/columndiscriminator/orm.xml new file mode 100644 index 000000000000..02e59602ee07 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/orm/test/columndiscriminator/orm.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file