• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting List values out of hibernate query

 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi-

my latest project is to add expanded category views in a tree
structure for my checkbook program found at www.3rdshiftcoder.com

it seems that part of this query is mapped to a class but
the data from the rest of it is in java.util.List lst = query.list()

i cant figure how to get at the data in the lst so i can
build my tree structure!

can someone please help? code below:
tx = session.beginTransaction();
Query query = session.createSQLQuery("select {c.*} "+
",down1.description as down1 "+
",down2.description as down2 "+
",down3.description as down3 "+
"from CATEGORY as c "+
" left outer join CATEGORY as down1 on down1.parentid = c.categoryid" +
" left outer join CATEGORY as down2 on down2.parentid = down1.categoryid" +
" left outer join CATEGORY as down3 on down3.parentid = down2.categoryid " +
"where c.PARENTID is null "+
"order by c.description, down1, down2, down3")
.addEntity("c",Category.class);

System.out.println("before");
java.util.List lst = query.list();


for ( Iterator iter = lst.iterator();
iter.hasNext(); ) {
Category mycat = (Category) iter.next();

System.out.println(mycat.getCategoryid() + " mstr");
// i can get values out of mycat but need them out of the lst too!
//cant seem to go from a List value to a string
//i posted this in hibernate forum in case someone needed to understand the query and the issue.

thanks for any assistance,
jim
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi-

i am going to another group (java beginner) in the forum.
i want to see if i can narrow this down in its simplest test
and not involve any hibernate discussion yet.

thanks,
jim
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi-

i am going to another group (java beginner) in the forum.
i want to see if i can narrow this down in its simplest test
and not involve any hibernate discussion yet.

thanks,
jim
 
rahul khanna
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it some time back.. though I don't have the source code at the moment .. will have it tommorrow

try something on the lines of when you do a list() take the result into a list of objects.
Iterate the list( no of rows retrieved) and each object is the type casted into a object array (one row), the size of array being the number of parameters (columns in one row) retrieved in the sql query.

Iterate over the array and do obj[i].getString() to retrive each column with in the row.

Hope this helps.
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rahul-

if you run across a code sample, i'd really like to see it.
i have tried this 1,000 different ways.

i learned that when you perorm .toString() on an object it
doesnt behave like i thought it did. it puts the object
in a funny string code.
it seems the minute i do query.list().get(0) i am stuck.

i'm guessing i'd have to do some type of mapping with a
collection and use
the iterator to go through it. it doesnt look like there
is a quick fix.

i could be wrong....

thanks,
jim
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rahul and everyone.
i can get it to work now.
i posted over in java beginners my proposed
solution. i had a mental block.
i cant believe how long i became stuck.
i know i havent coded java and hibernate
in over a 1/2 year but....

thanks for offering to help.
now a vision for a feature to my program
will get added!

jim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic