File tree Expand file tree Collapse file tree 7 files changed +133
-0
lines changed
hibernate-core/src/test/java/org/hibernate/orm/test/embeddable/discriminatorvalues Expand file tree Collapse file tree 7 files changed +133
-0
lines changed Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+ import jakarta .persistence .DiscriminatorColumn ;
8+ import jakarta .persistence .Embeddable ;
9+
10+ @ Embeddable
11+ @ DiscriminatorColumn (name = "animal_type" , length = 1 )
12+ public class Animal {
13+ private int age ;
14+
15+ private String name ;
16+ }
Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+ import jakarta .persistence .Embeddable ;
8+
9+ @ Embeddable
10+ public class Cat extends Mammal {
11+ // [...]
12+ }
Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+ import jakarta .persistence .Embeddable ;
8+
9+ @ Embeddable
10+ public class Dog extends Mammal {
11+ // [...]
12+ }
Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+ import org .hibernate .testing .orm .junit .DomainModel ;
8+ import org .hibernate .testing .orm .junit .SessionFactory ;
9+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
10+ import org .junit .jupiter .api .Test ;
11+
12+ import java .util .List ;
13+
14+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
15+
16+ @ DomainModel (
17+ annotatedClasses = {
18+ Animal .class ,
19+ Cat .class ,
20+ Dog .class ,
21+ Fish .class ,
22+ Mammal .class ,
23+ Owner .class
24+ }
25+ )
26+ @ SessionFactory
27+ public class EmbeddableInheritanceTest {
28+
29+ @ Test
30+ void testCatByMother (SessionFactoryScope scope ) {
31+ final List <Owner > owners = scope .fromSession (
32+ session ->
33+ session .createQuery ( "select o from Owner o where treat(o.pet as Cat).mother = :mother" ,
34+ Owner .class )
35+ .setParameter ( "mother" , "Chloe" )
36+ .getResultList () );
37+ assertNotNull ( owners );
38+ }
39+
40+ @ Test
41+ void testCatMothers (SessionFactoryScope scope ) {
42+ final List <String > owners = scope .fromSession (
43+ session ->
44+ session .createNamedQuery ( "catMothers" , String .class )
45+ .getResultList () );
46+ assertNotNull ( owners );
47+ }
48+ }
Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+ import jakarta .persistence .Embeddable ;
8+
9+ @ Embeddable
10+ public class Fish extends Animal {
11+ private int fins ;
12+ }
Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+ import jakarta .persistence .Embeddable ;
8+
9+ @ Embeddable
10+ public class Mammal extends Animal {
11+ private String mother ;
12+ }
Original file line number Diff line number Diff line change 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 .embeddable .discriminatorvalues ;
6+
7+
8+ import jakarta .persistence .Embedded ;
9+ import jakarta .persistence .Entity ;
10+ import jakarta .persistence .Id ;
11+ import jakarta .persistence .NamedQuery ;
12+
13+ @ Entity
14+ @ NamedQuery (name = "catMothers" , query = "select treat(o.pet as Cat).mother from Owner o" )
15+ public class Owner {
16+ @ Id
17+ private Long id ;
18+
19+ @ Embedded
20+ private Animal pet ;
21+ }
You can’t perform that action at this time.
0 commit comments