简体   繁体   中英

hibernate with out pojo classes

I'm fetching object list from session.createSQLQuery(). I didnt make any pojo classes for it because I don't want it This object contain 2 variables , I want to fetch those variables who can I

My code

    session = sessionfactory.openSession() ;

    query = session.createSQLQuery("select id from A_Cleanup") ;
    List Ids =  query.list() ;
    for (Iterator iterator = Ids.iterator(); iterator.hasNext(); iterator.next()){
        query = session.createSQLQuery("select distinct rec_category, a_id from a_cdr where a_id in (select id from alerts where al_id = :aid)")
                .setParameter("aid", Long.parseLong(Ids.get(0).toString())) ;
        java.util.List result = query.list() ;
        System.out.println("printing class object" +result.get(0).getClass()) ;

    }
    session.close() ;

Question:

result.get(0) is a object contain value rec_category and a_id. How can I fetch this variables ?

The result.get(0) returns an Object[] (in this case with 2 elements). So cast it first to Object[] , then retrieve each element separately and cast them to their proper types.

Object[] foo = (Object[]) result.get(0);
System.out.println(foo[0] + " and " + foo[1]); // Then cast each one to their real types

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM