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.  [ 1 post ] 
Author Message
 Post subject: Using SQL Functions with parameters within projections
PostPosted: Tue Oct 23, 2007 2:53 pm 
Newbie

Joined: Tue Oct 23, 2007 2:10 pm
Posts: 3
Hibernate version:
1.2.0GA

Name and version of the database you are using:
SQL 2005

Is there a better way to handle this type of SqlProjection:

Code:
        private IProjection CalculatedDistanceProjection(ICDBSearchCriteria criteria)
        {
            string[] columnAliases = {"distance"};
            IType[] types = {NHibernateUtil.Int32};

            string sqlCalculateDistance =
                String.Format("common.calculatedistance({0},{1},{2},{3}) as distance", "postalCode",
                              SetNullStringIfEmpty(criteria.PostalCode), SetNullStringIfEmpty(criteria.City),
                              SetNullStringIfEmpty(criteria.Statecode));

            return Projections.SqlProjection(sqlCalculateDistance, columnAliases, types);
        }


This function is called by:
Code:
projectionList.Add(CalculatedDistanceProjection(criteria), "Distance");


I tried subclassing the dialect and using register function within the constructor but I couldn't get it to work using ICriteria nor could I find any examples of using a SQL function within a projection.

This does work as shown, but it's dependent on supplying the "postalCode" field name as a string instead of a mapped field.


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

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.