Getting a single field from another table using Hibernate 3 mapping
843859Jan 13 2008 — edited Nov 20 2014I need to get a single field from another table that is joined to my table using a foreign key. I know I can get this by writing the SQL, and that I can get it by setting up a class that represents a very limited version of the other table. I know I could denormalize the data and put that field in my table. Is there a way using hibernate 3 mapping to get something like:
select t.*, o.data from my_table t
left join other_table o on o.pkey = t.fkey
into the class.
There is a many to one relationship between my_table and other_table. I don't want to get all of the other table, because it is quite wide and the query may return a lot of rows (the first table has about 200000 rows). And lazy fetching won't help, since I end up looking at all the rows I fetch.