This *looks* to be exactly what I'm looking for, however, I'm getting an
"inconsistent datatypes" error from Oracle.  Is there something I need to do
to get :id_list to be recognized as Longs?  I tried the query that Hibernate
is using, and substituted the test case parameters, and everything worked
fine.

My DAO method expects a list, and that's what I'm passing in.  Here's my
method signature:

    public List getHeadendNames(List headendIds) throws DAOException {
        Session ses = null;
        Headend headend = null;
        List headendList = Collections.synchronizedList(new
ArrayList(headendIds.size()));

        try {
            ses = HibernateSession.currentSession();

            Query q = ses.createQuery("from h in class
com.cable.comcast.dmc.itd.cct.persistence.Headend where h.id in (:id_list)
order by h.name");
            q.setParameterList("id_list", headendIds);

            List sorted = q.list();

And here's my test to call it:

        Headend h = new Headend();
        h.setId(new Long(2));
        headendList.add(h);
        h = new Headend();
        h.setId(new Long(3));
        headendList.add(h);
                List listWithNames = new ArrayList(headendList.size());
                
        listWithNames = dao.getHeadendNames(headendList);

Thanks,

Matt

-----Original Message-----
From: Gavin King [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 02, 2003 7:56 PM
To: Raible, Matt; [EMAIL PROTECTED]
Subject: RE: [Hibernate] Getting a sorted list of results


Try something like:

Query q = sess.createQuery("from h in class Headend where h.id in
(:id_list) order by h.name");
q.setParameterList("id_list", headendIds);
List sorted = q.list();

Note that this is might not be very good if the id List is very long...

> -----Original Message-----
> From: Raible, Matt [mailto:[EMAIL PROTECTED] 
> Sent: Friday, 3 January 2003 11:33 AM
> To: '[EMAIL PROTECTED]'
> Subject: [Hibernate] Getting a sorted list of results
> 
> 
> I am using the following method to get back a list of objects 
> based on ids. What I would prefer is to get back a list of 
> objects sorted by object.name. I know there's an easier way 
> to do this with hibernate, but I can't seem to find it.
> 
>             // loop through the list of headend ids and get 
> their names
>             for (int i = 0; i < headendIds.size(); i++) {
> 
>                 headend = (Headend) headendIds.get(i); // get the id
> 
>                 Long headendId = headend.getId();
>                 if (log.isDebugEnabled()) {
>                       log.debug("looking for headend with id: 
> " + headendId);
>                 }
>                 headend = (Headend) ses.load(Headend.class, 
> headendId); // get the headend
> 
>                 if (headend == null) {
>                     log.error("No headend name found for id: 
> " + headendId);
>                     throw new DAOException("No headend name 
> found for id: "
> +
>                                            headendId);
>                 } else {
>                       if (log.isDebugEnabled()) {
>                               log.debug("returning headend 
> with name: " + headend);
>                       }
>                 }
> 
>                 // replace the object in the list
>                 headendList.add(i, headend);
>             }
> 
> Thanks,
> 
> Matt
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf 
> _______________________________________________
> hibernate-devel mailing list [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
> 


********** CAUTION - Disclaimer **********
This message may contain privileged and confidential
information. If you are not the intended recipient of this
message (or responsible for delivery of the message to
such person) you are hereby notified that any use,
dissemination, distribution or reproduction of this message
is prohibited. If you have received this message in error,
you should destroy it and kindly notify the sender by reply
e-mail. Please advise immediately if you or your employer
do not consent to Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this
message that do not relate to the official business of
Expert Information Services Pty Ltd ("The Company")
shall be understood as neither given nor endorsed by it.

The Company advises that this e-mail and any attached
files should be scanned to detect viruses. The Company
accepts no liability for loss or damage (whether caused
by negligence or not) resulting from the use of any
attached files.
**EIS******** End of Disclaimer **********



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to