graeme1971 wrote:
Hibernate version: 3, with Alpha Annotations
I have the following section of code in my old Hibernate 2.1 codebase. I want to get a list of discriminators and originally did this by calling getSubclassClosure on an instance of EntityPersister. How can I do the some thing in Hibernate 3, given that getSubclassClosure no longer exists as a method?
Thanks, Graeme.
/**
* Load information about a discriminator into cache
*
* @param cls Class
* @throws DBConnectionException If an error occurs while accessing the hibernate information
* @throws IllegalArgumentException If the class is not mapped
*/
private void collectDiscrimators( Class cls ) throws DBConnectionException, IllegalArgumentException
{
ClassMetadata metaData = HibernateConnection.getInstance().getClassMetadata( cls );
if( metaData instanceof EntityPersister )
{
EntityPersister persister = (EntityPersister)metaData;
// get all classes that this entity contains (including self)
Class[] closure = persister.getSubclassClosure();
List discriminatorList = new ArrayList( closure.length );
for( int i = 0; i < closure.length; i++ )
{
Class classType = closure[i];
Object d = disciminatorClassMap.get( classType );
// add discriminator if not already in map
if( d == null )
{
d = getDiscriminatorForClass( classType );
// add to map
disciminatorClassMap.put( classType, d );
// should never be null
assert( d != null );
}
// add to list of discriminators
discriminatorList.add( d );
}
// add list to cache
disciminatorListClassMap.put( cls, discriminatorList );
}
else
{
throw new IllegalArgumentException( "Class: " + cls.getName() + " is not an instance of EntityPerister" );
}
}
I think I found the answer: Cast to SingleTableEntityPersister instead of EntityPersister...
Thanks anyway!
Rgds, Graeme.