-->
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 alias names in hibernate criteria api?
PostPosted: Mon Jun 07, 2010 3:59 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
Currently, I have the following...

DetachedCriteria criteria = DetachedCriteria.forClass(TpvTransContactMapping.class, "mapping");
criteria.createAlias("theTrans", "trans", Criteria.LEFT_JOIN); //Tpvtrans table
criteria.createAlias("account", "account", Criteria.LEFT_JOIN); //Account table
DetachedCriteria newCrit = criteria.createCriteria("parent", "contact"); //TpvContact table
newCrit.createCriteria("lastCall", "lastCall"); //back to Tpvtrans table
newCrit.createCriteria("rootTpvtrans", "root"); //back to Tpvtrans table

and I need to add something like this...
criteria.add(Restrictions.sqlRestriction("{contact}.callSeqEndDt > current_time - INTERVAL '{account}.monthsOfAudio months'"));

BUT in the docs, it only has {alias} which represents the row for table TpvTransContactMapping(alias = mapping) in this case. I seem to only be able to do {contact}.callSeqEndDt by using this line...

newCrit.add(Restrictions.sqlRestriction("{alias}.callSeqEndDt > current_time - INTERVAL '???? months'"));

which correctly does contact2_.callSeqEndDt correctly in the sql, BUT now I can't get the account.monthsOfAudio. Is there a way to do the first one or to get the alias's to print in the sqlRestriction correct?

NOTICE, to use the {alias}, I had to switch to newCrit so the target table was based on the parent(alias=contact) above.

thanks,
Dean

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


Top
 Profile  
 
 Post subject: Re: getting alias names in hibernate criteria api?
PostPosted: Mon Jun 07, 2010 5:42 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
turns out if your columns don't conflict, you can just type in the column names before aliasing. I didn't think that would work since all the columns were aliased to different names from hibernate but it seemed to work this time. I wonder how to do this if you want to get the hibernate alias name so you can specify table1alias.column and table2alias.column though. That would be nice and a little more robust in face of adding new columns.

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


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.