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(); + } +}