Skip to content

Commit 8d0cfa7

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

File tree

7 files changed

+207
-0
lines changed

7 files changed

+207
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.columndiscriminator;
6+
7+
import java.util.*;
8+
9+
public class Author {
10+
private Long id;
11+
private String name;
12+
private String email;
13+
private List<Book> books = new ArrayList<>();
14+
15+
public Author(String name, String email) {
16+
this.name = name;
17+
this.email = email;
18+
}
19+
20+
protected Author() {
21+
// default
22+
}
23+
24+
public Long id() {
25+
return id;
26+
}
27+
28+
public String name() {
29+
return name;
30+
}
31+
32+
public String email() {
33+
return email;
34+
}
35+
36+
public List<Book> books() {
37+
return books;
38+
}
39+
40+
public void addBook(Book book) {
41+
books.add(book);
42+
}
43+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.columndiscriminator;
6+
7+
public class Book {
8+
private Long id;
9+
private String title;
10+
private BookDetails details;
11+
12+
public Book(String title, BookDetails details) {
13+
this.title = title;
14+
this.details = details;
15+
}
16+
17+
protected Book() {
18+
// default
19+
}
20+
21+
public Long id() {
22+
return id;
23+
}
24+
25+
public String title() {
26+
return title;
27+
}
28+
29+
public BookDetails details() {
30+
return details;
31+
}
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.columndiscriminator;
6+
7+
public abstract class BookDetails {
8+
private String information;
9+
10+
protected BookDetails(String information) {
11+
this.information = information;
12+
}
13+
14+
protected BookDetails() {
15+
// default
16+
}
17+
18+
public String information() {
19+
return information;
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.columndiscriminator;
6+
7+
public class BoringBookDetails extends BookDetails {
8+
private String boringInformation;
9+
10+
public BoringBookDetails(String information, String boringInformation) {
11+
super(information);
12+
this.boringInformation = boringInformation;
13+
}
14+
15+
public BoringBookDetails() {
16+
// default
17+
}
18+
19+
public String boringInformation() {
20+
return boringInformation;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.columndiscriminator;
6+
7+
import org.hibernate.cfg.AvailableSettings;
8+
import org.hibernate.cfg.SchemaToolingSettings;
9+
import org.hibernate.testing.orm.junit.DomainModel;
10+
import org.hibernate.testing.orm.junit.ServiceRegistry;
11+
import org.hibernate.testing.orm.junit.SessionFactory;
12+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
13+
import org.hibernate.testing.orm.junit.Setting;
14+
import org.junit.jupiter.api.Test;
15+
16+
@DomainModel(xmlMappings = "org/hibernate/orm/test/columndiscriminator/orm.xml")
17+
@ServiceRegistry(settings = {
18+
@Setting(name = AvailableSettings.DEFAULT_SCHEMA, value = "GREET"),
19+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS, value = "true")
20+
})
21+
@SessionFactory
22+
class ColumnDiscrimnatorWithSchemaTest {
23+
24+
@Test
25+
void testIt(SessionFactoryScope scope) {
26+
scope.inTransaction( entityManager -> {
27+
var book = new Book( "The Art of Computer Programming",
28+
new SpecialBookDetails( "Hardcover", "Computer Science" ) );
29+
30+
var author = new Author( "Donald Knuth", "[email protected]" );
31+
author.addBook( book );
32+
entityManager.persist( author );
33+
} );
34+
}
35+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.columndiscriminator;
6+
7+
public class SpecialBookDetails extends BookDetails {
8+
private String specialInformation;
9+
10+
public SpecialBookDetails(String information, String specialInformation) {
11+
super(information);
12+
this.specialInformation = specialInformation;
13+
}
14+
15+
protected SpecialBookDetails() {
16+
// default
17+
}
18+
19+
public String specialInformation() {
20+
return specialInformation;
21+
}
22+
}
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)