Skip to content

Commit 9729649

Browse files
committed
HHH-11241 : test case (failing tests marked with FailureExpected)
(cherry picked from commit 3e52340)
1 parent 9a5df45 commit 9729649

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.test.join;
8+
9+
/**
10+
* @author Gail Badner
11+
*/
12+
public class BlogEntry extends Reportable
13+
{
14+
private String detail;
15+
16+
public String getDetail() {
17+
return detail;
18+
}
19+
public void setDetail(String detail) {
20+
this.detail = detail;
21+
}
22+
}
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.test.join;
8+
9+
import java.util.List;
10+
11+
/**
12+
* @author Gail Badner
13+
*/
14+
public class Bug extends Reportable {
15+
private List<String> detail;
16+
17+
public List<String> getDetail() {
18+
return detail;
19+
}
20+
public void setDetail(List<String> detail) {
21+
this.detail = detail;
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3+
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
4+
<hibernate-mapping package="org.hibernate.test.join">
5+
6+
<class name="Reportable">
7+
<id name="id" type="java.lang.Long">
8+
<generator class="increment"/>
9+
</id>
10+
<discriminator column="disc" type="string"/>
11+
<property name="reportedBy" />
12+
13+
<subclass name="Bug">
14+
<list cascade="all" name="detail">
15+
<key column="BUG_ID" />
16+
<index column="BUG_INDEX" type="int" />
17+
<element type="string"/>
18+
</list>
19+
</subclass>
20+
21+
<subclass name="BlogEntry">
22+
<join fetch="select" table="BLOG_ENTRY">
23+
<key column="BLOG_ENTRY_ID" />
24+
<property name="detail"/>
25+
</join>
26+
</subclass>
27+
28+
</class>
29+
30+
</hibernate-mapping>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.test.join;
8+
9+
/**
10+
* @author Gail Badner
11+
*/
12+
public abstract class Reportable {
13+
private Long id;
14+
private String reportedBy;
15+
16+
public Long getId() {
17+
return id;
18+
}
19+
public void setId(Long id) {
20+
this.id = id;
21+
}
22+
public String getReportedBy() {
23+
return reportedBy;
24+
}
25+
public void setReportedBy(String reportedBy) {
26+
this.reportedBy = reportedBy;
27+
}
28+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.test.join;
8+
9+
import org.junit.Test;
10+
11+
import org.hibernate.Session;
12+
import org.hibernate.Transaction;
13+
import org.hibernate.criterion.Restrictions;
14+
import org.hibernate.testing.FailureExpected;
15+
import org.hibernate.testing.TestForIssue;
16+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
17+
18+
import static org.junit.Assert.assertEquals;
19+
20+
/**
21+
* Two subclasses of Reportable each have a property with the same name:
22+
* Bug#detail and BlogEntry#detail. BlogEntry#detail is stored on a
23+
* join (secondary) table. Bug#detail is actually a collection, so its
24+
* values should be stored in a collection table.
25+
*
26+
* @author Gail Badner
27+
*/
28+
@TestForIssue( jiraKey = "HHH-11241" )
29+
public class SubclassesWithSamePropertyNameTest extends BaseCoreFunctionalTestCase {
30+
31+
@Override
32+
public String[] getMappings() {
33+
return new String[] { "join/Reportable.hbm.xml" };
34+
}
35+
36+
@Override
37+
protected void prepareTest() {
38+
Session s = openSession();
39+
s.getTransaction().begin();
40+
BlogEntry blogEntry = new BlogEntry();
41+
blogEntry.setDetail( "detail" );
42+
blogEntry.setReportedBy( "John Doe" );
43+
s.persist( blogEntry );
44+
s.getTransaction().commit();
45+
s.close();
46+
}
47+
48+
@Test
49+
@TestForIssue( jiraKey = "HHH-11241" )
50+
@FailureExpected( jiraKey = "HHH-11241" )
51+
public void testQuerySuperclass() {
52+
Session s = openSession();
53+
Transaction tx = s.beginTransaction();
54+
Reportable reportable = (Reportable) s.createQuery(
55+
"from Reportable where reportedBy='John Doe'"
56+
).uniqueResult();
57+
assertEquals( "John Doe", reportable.getReportedBy() );
58+
assertEquals( "detail", ( (BlogEntry) reportable ).getDetail() );
59+
tx.commit();
60+
s.close();
61+
}
62+
63+
@Test
64+
@TestForIssue( jiraKey = "HHH-11241" )
65+
@FailureExpected( jiraKey = "HHH-11241" )
66+
public void testCriteriaSuperclass() {
67+
Session s = openSession();
68+
Transaction tx = s.beginTransaction();
69+
Reportable reportable =
70+
(Reportable) s.createCriteria( Reportable.class, "r" )
71+
.add( Restrictions.eq( "r.reportedBy", "John Doe" ) )
72+
.uniqueResult();
73+
assertEquals( "John Doe", reportable.getReportedBy() );
74+
assertEquals( "detail", ( (BlogEntry) reportable ).getDetail() );
75+
tx.commit();
76+
s.close();
77+
}
78+
79+
@Test
80+
@TestForIssue( jiraKey = "HHH-11241" )
81+
public void testQuerySubclass() {
82+
Session s = openSession();
83+
Transaction tx = s.beginTransaction();
84+
BlogEntry blogEntry = (BlogEntry) s.createQuery(
85+
"from BlogEntry where reportedBy='John Doe'"
86+
).uniqueResult();
87+
assertEquals( "John Doe", blogEntry.getReportedBy() );
88+
assertEquals( "detail", ( blogEntry ).getDetail() );
89+
tx.commit();
90+
s.close();
91+
}
92+
93+
@Test
94+
@TestForIssue( jiraKey = "HHH-11241" )
95+
public void testCriteriaSubclass() {
96+
Session s = openSession();
97+
Transaction tx = s.beginTransaction();
98+
BlogEntry blogEntry =
99+
(BlogEntry) s.createCriteria( BlogEntry.class, "r" )
100+
.add( Restrictions.eq( "r.reportedBy", "John Doe" ) )
101+
.uniqueResult();
102+
assertEquals( "John Doe", blogEntry.getReportedBy() );
103+
assertEquals( "detail", ( blogEntry ).getDetail() );
104+
tx.commit();
105+
s.close();
106+
}
107+
}

0 commit comments

Comments
 (0)