Hi
This is description of my problem:
I have two tables: THREAD (id, name) and THREAD_STAMP (thread_id,user_id)
First table describes the forum thread , the second describes if the thread was read by particular user.
Now I want to get the list of threads but with info if the thread was read by particular user.
From the sql level it should enough to generate query like this:
select t.*,ts.* from THREAD t left outer join THREAD_STAMP ts ON t.id=ts.thread_id WHERE ts.user_id=givenvalue or ts.user_id is NULL;
So it could be done with only one select. It can be also well interpreted, if the user_id is not null in particular row it means that that thread was read by the user.
If I will follow the plain jdbc approach I can parse the jdbc result set and fill the list of container objects of class ThreadRow that has fields threadId, threadName and userId. I need that data only for reports so read only purpose.
But what if I would like to use Hibernate for such structures. Is it possible to automatically copy the data from database result set to the list of report objects ?. I have tried with createSqlQuery(...) but with that I need the class ThreadRow to be mapped which is impossible because it takes data from several tables. Also tried with dynamic initialization (constructor for ThreadRow with lot of params) but have no idea how to create mapping that generates above sql. The reason of all above is because of performance, it should work extremely fast.
Is there any way it could be done with Hibernate with also one database sql query.???
Bartek
|