Skip to content

Commit d2036cb

Browse files
committed
HHH-14351 Test showing that order by type discriminator desc fails
1 parent 52785ce commit d2036cb

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.hibernate.test.orderby;
2+
3+
import java.util.List;
4+
import javax.persistence.DiscriminatorValue;
5+
import javax.persistence.Entity;
6+
import javax.persistence.Id;
7+
8+
import org.hibernate.testing.TestForIssue;
9+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
10+
import org.junit.Test;
11+
12+
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
13+
import static org.junit.Assert.assertEquals;
14+
15+
/**
16+
* @author Christian Beikov
17+
*/
18+
public class OrderByTest extends BaseCoreFunctionalTestCase {
19+
20+
@Override
21+
protected Class[] getAnnotatedClasses() {
22+
return new Class[] {
23+
Person.class,
24+
P1.class,
25+
P2.class
26+
};
27+
}
28+
29+
@Override
30+
protected void prepareTest() throws Exception {
31+
doInHibernate(
32+
this::sessionFactory, session -> {
33+
session.persist( new P1( 1L, "abc" ) );
34+
session.persist( new P1( 2L, "abc" ) );
35+
session.persist( new P2( 3L, "def" ) );
36+
}
37+
);
38+
}
39+
40+
@Override
41+
protected void cleanupTest() throws Exception {
42+
doInHibernate(
43+
this::sessionFactory, session -> {
44+
session.createQuery( "delete from Person" ).executeUpdate();
45+
}
46+
);
47+
}
48+
49+
@Test
50+
@TestForIssue( jiraKey = "HHH-14351")
51+
public void testOrderBySqlNode() {
52+
doInHibernate(
53+
this::sessionFactory, session -> {
54+
List<Person> list = session.createQuery( "from Person p order by type(p) desc, p.id", Person.class )
55+
.getResultList();
56+
assertEquals( 3L, list.get( 0 ).getId().longValue() );
57+
assertEquals( 1L, list.get( 1 ).getId().longValue() );
58+
assertEquals( 2L, list.get( 2 ).getId().longValue() );
59+
}
60+
);
61+
}
62+
63+
@Entity(name = "Person")
64+
public static abstract class Person {
65+
@Id
66+
private Long id;
67+
private String name;
68+
69+
public Person() {
70+
}
71+
72+
public Person(Long id, String name) {
73+
this.id = id;
74+
this.name = name;
75+
}
76+
77+
public Long getId() {
78+
return id;
79+
}
80+
81+
public void setId(Long id) {
82+
this.id = id;
83+
}
84+
85+
public String getName() {
86+
return name;
87+
}
88+
89+
public void setName(String name) {
90+
this.name = name;
91+
}
92+
}
93+
94+
@Entity(name = "P1")
95+
@DiscriminatorValue( "P1" )
96+
public static class P1 extends Person {
97+
public P1() {
98+
}
99+
100+
public P1(Long id, String name) {
101+
super( id, name );
102+
}
103+
}
104+
105+
@Entity(name = "P2")
106+
@DiscriminatorValue( "P2" )
107+
public static class P2 extends Person {
108+
public P2() {
109+
}
110+
111+
public P2(Long id, String name) {
112+
super( id, name );
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)