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 Query/Criteria instead of SQLQuery for a view.
PostPosted: Tue Nov 22, 2011 12:40 pm 
Beginner
Beginner

Joined: Sun Jan 11, 2009 2:47 pm
Posts: 21
I am using an SQLQuery to load some entities from a view. The view is not mapped -- the entities are already mapped to another table.

Here is my code:

Code:
public class SampleDAO extends DAO<Sample,UUID> {

    ...
   
    @SuppressWarnings("unchecked")
    public List<Sample> findByAlliance (Alliance alliance) {
        return getSession().createSQLQuery("select * from [samples_with_alliances] where [alliance_id]=?")
                .addEntity(Sample.class)
                .setEntity(0, alliance)
                .list();
    }

}


Sample and Alliance are both mapped to their own tables in an XML mapping document.

[samples_with_alliances] is a database view (MSSQL) that returns all the columns required to load a Sample, plus an additional alliance_id column for searching by Alliance.

The above code is working exactly as expected. However, I don't feel comfortable using T-SQL flavored SQLQueries in my Hibernate DAO's. Is there a way to do this using HQL and a Query (or Criteria)?

Thanks!


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.