|
| 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