From 400afbb8c3e3bd82bc70ac7674beb32700d05afe Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Fri, 18 Nov 2016 17:31:32 -0800 Subject: [PATCH] HHH-11241 : test case (failing tests marked with FailureExpected) (cherry picked from commit 3e52340a927477a8c98becf8a8032a9a38425dde) --- .../org/hibernate/test/join/BlogEntry.java | 22 ++++ .../java/org/hibernate/test/join/Bug.java | 23 ++++ .../hibernate/test/join/Reportable.hbm.xml | 30 +++++ .../org/hibernate/test/join/Reportable.java | 28 +++++ .../SubclassesWithSamePropertyNameTest.java | 107 ++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/join/BlogEntry.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/join/Bug.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/join/Reportable.hbm.xml create mode 100644 hibernate-core/src/test/java/org/hibernate/test/join/Reportable.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/join/SubclassesWithSamePropertyNameTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/join/BlogEntry.java b/hibernate-core/src/test/java/org/hibernate/test/join/BlogEntry.java new file mode 100644 index 0000000000..119772f0b3 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/join/BlogEntry.java @@ -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 . + */ +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; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/join/Bug.java b/hibernate-core/src/test/java/org/hibernate/test/join/Bug.java new file mode 100644 index 0000000000..a723508023 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/join/Bug.java @@ -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 . + */ +package org.hibernate.test.join; + +import java.util.List; + +/** + * @author Gail Badner + */ +public class Bug extends Reportable { + private List detail; + + public List getDetail() { + return detail; + } + public void setDetail(List detail) { + this.detail = detail; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/join/Reportable.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/join/Reportable.hbm.xml new file mode 100644 index 0000000000..96cc9a3912 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/join/Reportable.hbm.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/test/join/Reportable.java b/hibernate-core/src/test/java/org/hibernate/test/join/Reportable.java new file mode 100644 index 0000000000..2ca052905b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/join/Reportable.java @@ -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 . + */ +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; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/join/SubclassesWithSamePropertyNameTest.java b/hibernate-core/src/test/java/org/hibernate/test/join/SubclassesWithSamePropertyNameTest.java new file mode 100644 index 0000000000..cfb2ecc256 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/join/SubclassesWithSamePropertyNameTest.java @@ -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 . + */ +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(); + } +}