-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-18988 Adapted test case from Jira issue https://hibernate.atlassi…
- Loading branch information
Showing
7 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Author.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
hibernate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BookDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...nate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/BoringBookDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...est/java/org/hibernate/orm/test/columndiscriminator/ColumnDiscrimnatorWithSchemaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ate-core/src/test/java/org/hibernate/orm/test/columndiscriminator/SpecialBookDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
hibernate-core/src/test/resources/org/hibernate/orm/test/columndiscriminator/orm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |