Folks,
I did not knwo where else to post my question..and in case this is not
the forum for these kind of things, please point me to the correct
direction..
Now to my question,
I have a requirement where i wil have to pass in a List of values to a
a db table for lookup.. i mean,
i have a table MY_TABLE on Oracle 9i, and the primary key is
MY_TABLE_ID and there are a few other fields, MY_NAME, MY_ADDRESS in
that as well.
i need to query this table for a variable list of MY_TABLE_IDs. How do
i do that in Hibernate ??
select * from MY_TABLE
where MY_TABLE_ID = any (my_table_id1, my_table_id2)
my_table_id1 and my_table_id2 are coming from my app, and this lenght
is also variable.. i might have just 1 id to pass to or more than 1.
any help in this regard is greatly appretiated...
thanks
-CD
Philip Reimer - 18 May 2006 15:58 GMT
gangsterss schrieb:
> Folks,
>
[quoted text clipped - 23 lines]
> thanks
> -CD
maybe like so:
//named parameter list
List ids = new ArrayList();
ids.add("my_table_id1");
ids.add("my_table_id2");
Query q = sess.createQuery("from MY_TABLE m where m.MY_TABLE_ID in
(:idsList)");
q.setParameterList("idsList", ids);
List result = q.list();
gangsterss - 18 May 2006 17:14 GMT
thanks Philip, but i need to write this in HQL. not in the java code..
thanks,
Oliver Wong - 18 May 2006 17:48 GMT
> thanks Philip, but i need to write this in HQL. not in the java code..
Earlier, you said:
<quote>
my_table_id1 and my_table_id2 are coming from my app
</quote>
which means you cannot possibly hardcode the query directly in HQL.
There's going to be some Java involved.
- Oliver
gangsterss - 18 May 2006 18:23 GMT
Ooh okay. Thanks...
One more question...
I have a table from which i can get multiple values for a field and i
need to retrieve ALL of those values, how do i do that in HQL??
say i have a sub table which has subvalue1 and subvalue2 rows for each
id. I need to get all the subValues associated with any id. Can i say
in my DTO that subvalue is a list ??
now i am retreveing only single value for each id, i need to get back
multiple values. Please guide me thru this asap...
thanks a lott...
Oliver Wong - 19 May 2006 15:01 GMT
> Ooh okay. Thanks...
> One more question...
[quoted text clipped - 7 lines]
> now i am retreveing only single value for each id, i need to get back
> multiple values. Please guide me thru this asap...
I'm not familiar with the terminology you're using. I know of "table",
"column" and "row", but not "field" nor "subtable".
Usually, rows are not named. When you say "subvalue1 and subvalue2
rows", are you sure you don't mean "subvalue1 and subvalue2 columns"?
- Oliver
gangsterss - 19 May 2006 15:28 GMT
Hi Oliver,
i meant values of that colum are subvalue1 and subvalue2. No worries, i
figured it out.. instead of having hibernate generate a list for me.. i
am doing that on my appilicaton side...
thanks for all your help....
-Shashi