HHH-4036 EntityMetamodel entityNameByInheritenceClassNameMap field used inconsistently
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19717 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
1cec58314d
commit
e630fde1aa
|
@ -56,7 +56,7 @@ public interface Instantiator extends Serializable {
|
|||
* or component which this Instantiator instantiates.
|
||||
*
|
||||
* @param object The object to be checked.
|
||||
* @return True is the object does respresent an instance of the underlying
|
||||
* @return True is the object does represent an instance of the underlying
|
||||
* entity/component.
|
||||
*/
|
||||
public boolean isInstance(Object object);
|
||||
|
|
|
@ -121,7 +121,7 @@ public class EntityMetamodel implements Serializable {
|
|||
private final boolean inherited;
|
||||
private final boolean hasSubclasses;
|
||||
private final Set subclassEntityNames = new HashSet();
|
||||
private final Map entityNameByInheritenceClassNameMap = new HashMap();
|
||||
private final Map entityNameByInheritenceClassMap = new HashMap();
|
||||
|
||||
private final EntityEntityModeToTuplizerMapping tuplizerMapping;
|
||||
|
||||
|
@ -311,11 +311,11 @@ public class EntityMetamodel implements Serializable {
|
|||
subclassEntityNames.add( name );
|
||||
|
||||
if ( persistentClass.hasPojoRepresentation() ) {
|
||||
entityNameByInheritenceClassNameMap.put( persistentClass.getMappedClass(), persistentClass.getEntityName() );
|
||||
entityNameByInheritenceClassMap.put( persistentClass.getMappedClass(), persistentClass.getEntityName() );
|
||||
iter = persistentClass.getSubclassIterator();
|
||||
while ( iter.hasNext() ) {
|
||||
final PersistentClass pc = ( PersistentClass ) iter.next();
|
||||
entityNameByInheritenceClassNameMap.put( pc.getMappedClass(), pc.getEntityName() );
|
||||
entityNameByInheritenceClassMap.put( pc.getMappedClass(), pc.getEntityName() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -569,13 +569,13 @@ public class EntityMetamodel implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the entity-name mapped to the given class within our inheritence hierarchy, if any.
|
||||
* Return the entity-name mapped to the given class within our inheritance hierarchy, if any.
|
||||
*
|
||||
* @param inheritenceClass The class for which to resolve the entity-name.
|
||||
* @return The mapped entity-name, or null if no such mapping was found.
|
||||
*/
|
||||
public String findEntityNameByEntityClass(Class inheritenceClass) {
|
||||
return ( String ) entityNameByInheritenceClassNameMap.get( inheritenceClass.getName() );
|
||||
return ( String ) entityNameByInheritenceClassMap.get( inheritenceClass );
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// $Id: Car.java 7087 2005-06-08 18:23:44Z steveebersole $
|
||||
package org.hibernate.test.entityname;
|
||||
|
||||
/**
|
||||
* Implementation of Car.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Car extends Vehicle {
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package org.hibernate.test.entityname;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.junit.functional.FunctionalTestCase;
|
||||
/**
|
||||
*
|
||||
* @author stliu
|
||||
*
|
||||
*/
|
||||
public class EntityNameFromSubClassTest extends FunctionalTestCase {
|
||||
|
||||
public EntityNameFromSubClassTest(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
public void testEntityName() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Person stliu = new Person();
|
||||
stliu.setName("stliu");
|
||||
Car golf = new Car();
|
||||
golf.setOwner("stliu");
|
||||
stliu.getCars().add(golf);
|
||||
s.save(stliu);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s=openSession();
|
||||
s.beginTransaction();
|
||||
Person p = (Person)s.get(Person.class, stliu.getId());
|
||||
assertEquals(1, p.getCars().size());
|
||||
assertEquals(Car.class, p.getCars().iterator().next().getClass());
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public String[] getMappings() {
|
||||
return new String[] { "entityname/Vehicle.hbm.xml" };
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.hibernate.test.entityname;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
/**
|
||||
*
|
||||
* @author stliu
|
||||
*
|
||||
*/
|
||||
public class Person {
|
||||
private Long id;
|
||||
private String Name;
|
||||
private Set cars = new HashSet();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public Set getCars() {
|
||||
return cars;
|
||||
}
|
||||
|
||||
public void setCars(Set cars) {
|
||||
this.cars = cars;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?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.entityname">
|
||||
|
||||
<!-- Vehicle represents an abstract root of a union-subclass hierarchy -->
|
||||
<class name="Vehicle" abstract="true" entity-name="VEHICLE" discriminator-value="V">
|
||||
<id name="id" access="field" type="long">
|
||||
<generator class="increment"/>
|
||||
</id>
|
||||
<discriminator column="TYPE" type="string" />
|
||||
<property name="vin" type="string"/>
|
||||
<property name="owner" type="string"/>
|
||||
|
||||
<!-- Car represents a concrete leaf of a union-subclass hierarchy with no concrete super -->
|
||||
<subclass name="Car" entity-name="CAR" discriminator-value="C"/>
|
||||
</class>
|
||||
<class name="Person">
|
||||
<id name="id">
|
||||
<generator class="increment" />
|
||||
</id>
|
||||
<property name="name" />
|
||||
<set name="cars" cascade="all">
|
||||
<key column="car_id"/>
|
||||
<one-to-many entity-name="VEHICLE"/>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,29 @@
|
|||
// $Id: Vehicle.java 7087 2005-06-08 18:23:44Z steveebersole $
|
||||
package org.hibernate.test.entityname;
|
||||
|
||||
/**
|
||||
* Implementation of Vehicle.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class Vehicle {
|
||||
private Long id;
|
||||
private String vin;
|
||||
private String owner;
|
||||
|
||||
public String getVin() {
|
||||
return vin;
|
||||
}
|
||||
|
||||
public void setVin(String vin) {
|
||||
this.vin = vin;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue