-->
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: Custom Criterion
PostPosted: Fri Sep 23, 2005 8:57 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I need to write a custom criterion to check for inheritance. My desire is to use it like this:

Code:

Criteria getDomesticCars = session.createCriteria( Car.class )
    .add( new ExtendsCriteria( "manufacturer", DomesticManufacturer.class ) )
    .list( );


Basically, what I need to do is:

1. Determine the inheritance strategy (table-per-subclass, discriminator, or mixed)
2. Get the discriminator column if present
3. Get the discriminator values and/or joined tables involved
4. Identify the discriminator values represent the specified class or any of its subclasses (as defined in the mapping)
5. Construct a SQL query string (where discriminator in (x, y, z, ...) or where id in (select id from joined_table))

I'm having some trouble with 1-3. I've looked through the API documentation at CriteriaQuery, SessionFactoryImplementor, and EntityPersister and I haven't seen any methods resembling hasDiscriminator( ) or getDiscriminator( ) or getJoinedTable( ). Am I looking in the right place? If not, where should I be looking? Also, are custom Criterion implementations future-proof, or are they tied to implementions (vice interfaces)?

Thanks in advance,

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 9:10 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I think I found what I was looking for:

Code:
SessionFactoryImplementor sfi = criteriaQuery.getFactory( );
EntityPersister ep = sfi.getEntityPersister( ??? );
if( ep instanceof Loadable )
{
    Loadable l = (Loadable)ep;
    Type discriminatorType = l.getDiscriminatorType( );
    if( l.hasSubclasses( ) )
    {
        ...
    }
}


Question: what goes where I put ???. The parameter is entityName... is that the Java class name of the entity that I am interested in? Second, loadable has a method call getSubclassForDiscriminatorValue( )... is there a corresponding getDiscriminatorValueForSubclass( ) method anywhere?

Am I on the right track?

- Jesse


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.