HHH-11241 : test case (failing tests marked with FailureExpected)

(cherry picked from commit 3e52340a92)
This commit is contained in:
Gail Badner 2016-11-18 17:31:32 -08:00
parent 9a5df451b6
commit 9729649615
5 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,22 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.join;
/**
* @author Gail Badner
*/
public class BlogEntry extends Reportable
{
private String detail;
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
}

View File

@ -0,0 +1,23 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.join;
import java.util.List;
/**
* @author Gail Badner
*/
public class Bug extends Reportable {
private List<String> detail;
public List<String> getDetail() {
return detail;
}
public void setDetail(List<String> detail) {
this.detail = detail;
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.join">
<class name="Reportable">
<id name="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<discriminator column="disc" type="string"/>
<property name="reportedBy" />
<subclass name="Bug">
<list cascade="all" name="detail">
<key column="BUG_ID" />
<index column="BUG_INDEX" type="int" />
<element type="string"/>
</list>
</subclass>
<subclass name="BlogEntry">
<join fetch="select" table="BLOG_ENTRY">
<key column="BLOG_ENTRY_ID" />
<property name="detail"/>
</join>
</subclass>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,28 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.join;
/**
* @author Gail Badner
*/
public abstract class Reportable {
private Long id;
private String reportedBy;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getReportedBy() {
return reportedBy;
}
public void setReportedBy(String reportedBy) {
this.reportedBy = reportedBy;
}
}

View File

@ -0,0 +1,107 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.join;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
/**
* Two subclasses of Reportable each have a property with the same name:
* Bug#detail and BlogEntry#detail. BlogEntry#detail is stored on a
* join (secondary) table. Bug#detail is actually a collection, so its
* values should be stored in a collection table.
*
* @author Gail Badner
*/
@TestForIssue( jiraKey = "HHH-11241" )
public class SubclassesWithSamePropertyNameTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] { "join/Reportable.hbm.xml" };
}
@Override
protected void prepareTest() {
Session s = openSession();
s.getTransaction().begin();
BlogEntry blogEntry = new BlogEntry();
blogEntry.setDetail( "detail" );
blogEntry.setReportedBy( "John Doe" );
s.persist( blogEntry );
s.getTransaction().commit();
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-11241" )
@FailureExpected( jiraKey = "HHH-11241" )
public void testQuerySuperclass() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Reportable reportable = (Reportable) s.createQuery(
"from Reportable where reportedBy='John Doe'"
).uniqueResult();
assertEquals( "John Doe", reportable.getReportedBy() );
assertEquals( "detail", ( (BlogEntry) reportable ).getDetail() );
tx.commit();
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-11241" )
@FailureExpected( jiraKey = "HHH-11241" )
public void testCriteriaSuperclass() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Reportable reportable =
(Reportable) s.createCriteria( Reportable.class, "r" )
.add( Restrictions.eq( "r.reportedBy", "John Doe" ) )
.uniqueResult();
assertEquals( "John Doe", reportable.getReportedBy() );
assertEquals( "detail", ( (BlogEntry) reportable ).getDetail() );
tx.commit();
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-11241" )
public void testQuerySubclass() {
Session s = openSession();
Transaction tx = s.beginTransaction();
BlogEntry blogEntry = (BlogEntry) s.createQuery(
"from BlogEntry where reportedBy='John Doe'"
).uniqueResult();
assertEquals( "John Doe", blogEntry.getReportedBy() );
assertEquals( "detail", ( blogEntry ).getDetail() );
tx.commit();
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-11241" )
public void testCriteriaSubclass() {
Session s = openSession();
Transaction tx = s.beginTransaction();
BlogEntry blogEntry =
(BlogEntry) s.createCriteria( BlogEntry.class, "r" )
.add( Restrictions.eq( "r.reportedBy", "John Doe" ) )
.uniqueResult();
assertEquals( "John Doe", blogEntry.getReportedBy() );
assertEquals( "detail", ( blogEntry ).getDetail() );
tx.commit();
s.close();
}
}