-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Getting a list of discriminators...
PostPosted: Mon Jan 31, 2005 11:50 am 
Newbie

Joined: Tue Jun 22, 2004 9:26 am
Posts: 4
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" );
}
}


Top
 Profile  
 
 Post subject: Re: Getting a list of discriminators...
PostPosted: Mon Jan 31, 2005 1:10 pm 
Newbie

Joined: Tue Jun 22, 2004 9:26 am
Posts: 4
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.