Skip to content

Commit bcbbc66

Browse files
cigalybeikov
authored andcommitted
HHH-18988 Adapted test case from Jira issue https://hibernate.atlassian.net/browse/HHH-18988
1 parent 59d3dec commit bcbbc66

File tree

7 files changed

+219
-0
lines changed

7 files changed

+219
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.columndiscriminator;
8+
9+
import java.util.*;
10+
11+
public class Author {
12+
private Long id;
13+
private String name;
14+
private String email;
15+
private List<Book> books = new ArrayList<>();
16+
17+
public Author(String name, String email) {
18+
this.name = name;
19+
this.email = email;
20+
}
21+
22+
protected Author() {
23+
// default
24+
}
25+
26+
public Long id() {
27+
return id;
28+
}
29+
30+
public String name() {
31+
return name;
32+
}
33+
34+
public String email() {
35+
return email;
36+
}
37+
38+
public List<Book> books() {
39+
return books;
40+
}
41+
42+
public void addBook(Book book) {
43+
books.add(book);
44+
}
45+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.columndiscriminator;
8+
9+
public class Book {
10+
private Long id;
11+
private String title;
12+
private BookDetails details;
13+
14+
public Book(String title, BookDetails details) {
15+
this.title = title;
16+
this.details = details;
17+
}
18+
19+
protected Book() {
20+
// default
21+
}
22+
23+
public Long id() {
24+
return id;
25+
}
26+
27+
public String title() {
28+
return title;
29+
}
30+
31+
public BookDetails details() {
32+
return details;
33+
}
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.columndiscriminator;
8+
9+
public abstract class BookDetails {
10+
private String information;
11+
12+
protected BookDetails(String information) {
13+
this.information = information;
14+
}
15+
16+
protected BookDetails() {
17+
// default
18+
}
19+
20+
public String information() {
21+
return information;
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.columndiscriminator;
8+
9+
public class BoringBookDetails extends BookDetails {
10+
private String boringInformation;
11+
12+
public BoringBookDetails(String information, String boringInformation) {
13+
super(information);
14+
this.boringInformation = boringInformation;
15+
}
16+
17+
public BoringBookDetails() {
18+
// default
19+
}
20+
21+
public String boringInformation() {
22+
return boringInformation;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.columndiscriminator;
8+
9+
import org.hibernate.cfg.AvailableSettings;
10+
import org.hibernate.cfg.SchemaToolingSettings;
11+
import org.hibernate.testing.orm.junit.DomainModel;
12+
import org.hibernate.testing.orm.junit.ServiceRegistry;
13+
import org.hibernate.testing.orm.junit.SessionFactory;
14+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
15+
import org.hibernate.testing.orm.junit.Setting;
16+
import org.junit.jupiter.api.Test;
17+
18+
@DomainModel(xmlMappings = "org/hibernate/orm/test/columndiscriminator/orm.xml")
19+
@ServiceRegistry(settings = {
20+
@Setting(name = AvailableSettings.DEFAULT_SCHEMA, value = "GREET"),
21+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS, value = "true")
22+
})
23+
@SessionFactory
24+
class ColumnDiscrimnatorWithSchemaTest {
25+
26+
@Test
27+
void testIt(SessionFactoryScope scope) {
28+
scope.inTransaction( entityManager -> {
29+
var book = new Book( "The Art of Computer Programming",
30+
new SpecialBookDetails( "Hardcover", "Computer Science" ) );
31+
32+
var author = new Author( "Donald Knuth", "[email protected]" );
33+
author.addBook( book );
34+
entityManager.persist( author );
35+
} );
36+
}
37+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.columndiscriminator;
8+
9+
public class SpecialBookDetails extends BookDetails {
10+
private String specialInformation;
11+
12+
public SpecialBookDetails(String information, String specialInformation) {
13+
super(information);
14+
this.specialInformation = specialInformation;
15+
}
16+
17+
protected SpecialBookDetails() {
18+
// default
19+
}
20+
21+
public String specialInformation() {
22+
return specialInformation;
23+
}
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entity-mappings xmlns="https://jakarta.ee/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm/orm_3_1.xsd"
4+
version="3.1">
5+
<entity class="org.hibernate.orm.test.columndiscriminator.Book" access="FIELD">
6+
<attributes>
7+
<id name="id">
8+
<generated-value strategy="AUTO"/>
9+
</id>
10+
11+
<embedded name="details"/>
12+
</attributes>
13+
</entity>
14+
15+
<entity class="org.hibernate.orm.test.columndiscriminator.Author" access="FIELD">
16+
<attributes>
17+
<id name="id">
18+
<generated-value strategy="AUTO"/>
19+
</id>
20+
21+
<one-to-many name="books" orphan-removal="true">
22+
<cascade>
23+
<cascade-all/>
24+
</cascade>
25+
</one-to-many>
26+
</attributes>
27+
</entity>
28+
29+
<embeddable class="org.hibernate.orm.test.columndiscriminator.BookDetails" access="FIELD"/>
30+
<embeddable class="org.hibernate.orm.test.columndiscriminator.SpecialBookDetails" access="FIELD"/>
31+
<embeddable class="org.hibernate.orm.test.columndiscriminator.BoringBookDetails" access="FIELD"/>
32+
</entity-mappings>

0 commit comments

Comments
 (0)