-->
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: Criteria Queries: Get entity and additional columns?
PostPosted: Mon Nov 13, 2006 11:10 am 
Newbie

Joined: Fri Jun 30, 2006 7:00 pm
Posts: 6
Is there a way, using criteria queries to extract an entity as well as additional columns associated with that entity? I'm using Postgres GIS queries to determine the distance of an entity, but I can't seem to get criteria queries to do what I want. If I use native SQL, I can do this:

Code:
session.createSQL("select {myentity.*}, distance(the_geom, MakePoint(...)) as distance ...")
    .addEntity("myentity", EntityClass.class)
    .addScalar("distance")
    .list()


But there does not seem to be a corresponding way of doing this using Criteria queries. I've managed to get this to sort of work by doing something like:

Code:
        criteria.setProjection(Projections.projectionList()
            .add(Projections.sqlProjection("*", new String[]{"id"}, new Type[]{Hibernate.entity(getEntityClass())}))
            .add(Projections.sqlProjection(
                "distance_sphere(the_geom, MakePoint(-75.25, 39.88)) as distance",
                new String[]{"distance"},
                new Type[]{Hibernate.DOUBLE}))
        );
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


But this does a query for each results returned based on ID, not the most efficient way to do what I want.

Am I relegated to building up a native SQL string? Or is there a way to get the Criteria Query API to do what I want?

Thanks!
David


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.