Skip to content

Commit

Permalink
HHH-18988 Adapted test case from Jira issue https://hibernate.atlassi…
Browse files Browse the repository at this point in the history
  • Loading branch information
cigaly authored and beikov committed Feb 11, 2025
1 parent 59d3dec commit bcbbc66
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<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,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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.DomainModel;
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
class 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,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;
}
}
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>

0 comments on commit bcbbc66

Please sign in to comment.