|
26 | 26 | import static org.junit.Assert.assertEquals; |
27 | 27 | import static org.junit.Assert.assertNotNull; |
28 | 28 |
|
| 29 | +import java.util.HashSet; |
| 30 | +import java.util.Set; |
| 31 | + |
| 32 | +import javax.persistence.Column; |
| 33 | +import javax.persistence.Entity; |
| 34 | +import javax.persistence.FetchType; |
| 35 | +import javax.persistence.GeneratedValue; |
| 36 | +import javax.persistence.Id; |
| 37 | +import javax.persistence.Inheritance; |
| 38 | +import javax.persistence.InheritanceType; |
| 39 | +import javax.persistence.JoinColumn; |
| 40 | +import javax.persistence.ManyToOne; |
| 41 | +import javax.persistence.OneToMany; |
| 42 | +import javax.persistence.Table; |
| 43 | + |
29 | 44 | import org.hibernate.Session; |
30 | 45 | import org.hibernate.Transaction; |
31 | 46 | import org.hibernate.testing.TestForIssue; |
|
34 | 49 |
|
35 | 50 | /** |
36 | 51 | * @author Emmanuel Bernard |
| 52 | + * @author Brett Meyer |
37 | 53 | */ |
38 | 54 | public class QuoteTest extends BaseCoreFunctionalTestCase { |
39 | 55 |
|
@@ -80,14 +96,68 @@ public void testDoubleQuoteJoinColumn() { |
80 | 96 | s.getTransaction().commit(); |
81 | 97 | s.close(); |
82 | 98 | } |
| 99 | + |
| 100 | + @Test |
| 101 | + @TestForIssue(jiraKey = "HHH-2988") |
| 102 | + public void testUnionSubclassEntityQuoting() { |
| 103 | + Session s = openSession(); |
| 104 | + s.beginTransaction(); |
| 105 | + Container container1 = new Container(); |
| 106 | + Container container2 = new Container(); |
| 107 | + SimpleItem simpleItem = new SimpleItem(); |
| 108 | + |
| 109 | + container1.items.add( container2 ); |
| 110 | + container1.items.add( simpleItem ); |
| 111 | + container2.parent = container1; |
| 112 | + simpleItem.parent = container1; |
| 113 | + |
| 114 | + s.persist( simpleItem ); |
| 115 | + s.persist( container2 ); |
| 116 | + s.persist( container1 ); |
| 117 | + s.getTransaction().commit(); |
| 118 | + s.clear(); |
| 119 | + |
| 120 | + Container result = (Container) s.get( Container.class, container1.id ); |
| 121 | + assertNotNull( result ); |
| 122 | + assertNotNull( result.items ); |
| 123 | + assertEquals( 2, result.items.size() ); |
| 124 | + } |
83 | 125 |
|
84 | 126 | @Override |
85 | 127 | protected Class[] getAnnotatedClasses() { |
86 | 128 | return new Class[] { |
87 | 129 | User.class, |
88 | 130 | Role.class, |
89 | 131 | Phone.class, |
90 | | - House.class |
| 132 | + House.class, |
| 133 | + Container.class, |
| 134 | + SimpleItem.class |
91 | 135 | }; |
92 | 136 | } |
| 137 | + |
| 138 | + @Entity |
| 139 | + @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) |
| 140 | + private static abstract class Item { |
| 141 | + |
| 142 | + @Id @GeneratedValue |
| 143 | + @Column(name = "`ID`") |
| 144 | + protected long id; |
| 145 | + |
| 146 | + @ManyToOne(fetch = FetchType.LAZY) |
| 147 | + @JoinColumn(name = "`ParentID`") |
| 148 | + protected Container parent; |
| 149 | + } |
| 150 | + |
| 151 | + @Entity |
| 152 | + @Table(name = "`CoNTaiNeR`") |
| 153 | + private static class Container extends Item { |
| 154 | + |
| 155 | + @OneToMany(mappedBy = "parent", targetEntity = Item.class) |
| 156 | + private Set<Item> items = new HashSet<Item>( 0 ); |
| 157 | + } |
| 158 | + |
| 159 | + @Entity |
| 160 | + @Table(name = "`SimpleItem`") |
| 161 | + private static class SimpleItem extends Item { |
| 162 | + } |
93 | 163 | } |
0 commit comments