HHH-3636 test case + fix

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15674 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Chris Bredesen 2008-12-10 01:47:56 +00:00
parent 19e258ce5a
commit ff1be35e7d
6 changed files with 154 additions and 5 deletions

View File

@ -2884,8 +2884,8 @@ public abstract class AbstractEntityPersister
String[] columnAliases = getSubclassColumnAliasClosure();
String[] columns = getSubclassColumnClosure();
for ( int i = 0; i < subclassColumnNumbers.length; i++ ) {
if ( subclassColumnSelectableClosure[i] ) {
int columnNumber = subclassColumnNumbers[i];
int columnNumber = subclassColumnNumbers[i];
if ( subclassColumnSelectableClosure[columnNumber] ) {
final String subalias = generateTableAlias( getRootAlias(), columnTableNumbers[columnNumber] );
selectFragment.addColumn( subalias, columns[columnNumber], columnAliases[columnNumber] );
}

View File

@ -0,0 +1,33 @@
package org.hibernate.test.collection.original;
public class Animal {
long id;
String name;
boolean boolvar;
Zoo zoo;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
public String getName() {
return name;
}
public void setName( String name ) {
this.name = name;
}
public boolean isBoolvar() {
return boolvar;
}
public void setBoolvar(boolean boolvar) {
this.boolvar = boolvar;
}
public Zoo getZoo() {
return zoo;
}
public void setZoo(Zoo zoo) {
this.zoo = zoo;
}
}

View File

@ -22,7 +22,7 @@ public class CollectionTest extends FunctionalTestCase {
}
public String[] getMappings() {
return new String[] { "collection/original/UserPermissions.hbm.xml" };
return new String[] { "collection/original/UserPermissions.hbm.xml", "collection/original/Zoo.hbm.xml" };
}
public static Test suite() {
@ -223,6 +223,27 @@ public class CollectionTest extends FunctionalTestCase {
s.close();
}
// HHH-3636
public void testCollectionInheritance() {
Session s = openSession();
Transaction t = s.beginTransaction();
Zoo zoo = new Zoo();
Mammal m = new Mammal();
m.setMammalName( "name1" );
m.setMammalName2( "name2" );
m.setMammalName3( "name3" );
m.setZoo( zoo );
zoo.getAnimals().add( m );
Long id = ( Long ) s.save( zoo );
t.commit();
s.close();
}
s = openSession();
t = s.beginTransaction();
Zoo found = ( Zoo ) s.get( Zoo.class, id );
found.getAnimals().size();
s.delete( found );
t.commit();
s.close();
}
}

View File

@ -0,0 +1,34 @@
package org.hibernate.test.collection.original;
public class Mammal extends Animal {
private String mammalName;
private String mammalName2;
private String mammalName3;
public String getMammalName() {
return mammalName;
}
public void setMammalName(String mammalName) {
this.mammalName = mammalName;
}
public String getMammalName2() {
return mammalName2;
}
public void setMammalName2(String mammalName2) {
this.mammalName2 = mammalName2;
}
public String getMammalName3() {
return mammalName3;
}
public void setMammalName3(String mammalName3) {
this.mammalName3 = mammalName3;
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.collection.original">
<class name="Zoo">
<id name="id" type="long">
<generator class="native" />
</id>
<list name="animals" cascade="save-update,delete">
<key column="Zoo_id" not-null="true" />
<list-index column="list_index" />
<one-to-many class="Animal" not-found="ignore" />
</list>
</class>
<class name="Animal" discriminator-value="ANIMAL">
<id name="id" column="ID" type="long">
<generator class="native" />
</id>
<discriminator column="discriminator" type="string" />
<property name="name"/>
<many-to-one name="zoo" class="Zoo" cascade="save-update,delete" />
</class>
<subclass name="Mammal" discriminator-value="MAMMAL" extends="Animal">
<join fetch="select" table="AnimalMammal">
<key column="Animal_id" />
<property name="mammalName" />
<property name="mammalName2" />
<property name="mammalName3" />
</join>
</subclass>
</hibernate-mapping>

View File

@ -0,0 +1,24 @@
package org.hibernate.test.collection.original;
import java.util.ArrayList;
import java.util.List;
public class Zoo {
long id;
List animals = new ArrayList();
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
public List getAnimals() {
return animals;
}
public void setAnimals(List animals) {
this.animals = animals;
}
}