Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ private EmbeddableDiscriminatorMapping generateDiscriminatorMapping(
return new ExplicitColumnDiscriminatorMappingImpl(
this,
name,
bootDescriptor.getTable().getName(),
bootDescriptor.getTable().getQualifiedName( creationContext.getSqlStringGenerationContext() ),
discriminatorColumnExpression,
isFormula,
!isFormula,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.columndiscriminator;

import java.util.*;

public class Author {
private Long id;
private String name;
private String email;
private List<Book> 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<Book> books() {
return books;
}

public void addBook(Book book) {
books.add(book);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
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", "[email protected]" );
author.addBook( book );
entityManager.persist( author );
} );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="https://jakarta.ee/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm/orm_3_1.xsd"
version="3.1">
<entity class="org.hibernate.orm.test.columndiscriminator.Book" access="FIELD">
<attributes>
<id name="id">
<generated-value strategy="AUTO"/>
</id>

<embedded name="details"/>
</attributes>
</entity>

<entity class="org.hibernate.orm.test.columndiscriminator.Author" access="FIELD">
<attributes>
<id name="id">
<generated-value strategy="AUTO"/>
</id>

<one-to-many name="books" orphan-removal="true">
<cascade>
<cascade-all/>
</cascade>
</one-to-many>
</attributes>
</entity>

<embeddable class="org.hibernate.orm.test.columndiscriminator.BookDetails" access="FIELD"/>
<embeddable class="org.hibernate.orm.test.columndiscriminator.SpecialBookDetails" access="FIELD"/>
<embeddable class="org.hibernate.orm.test.columndiscriminator.BoringBookDetails" access="FIELD"/>
</entity-mappings>
Loading