The hibernate mapping file:
your beans:
then your query:
then when you do a q.list() you will get instances of TableA beans, that contain a nested (joined) TableB, that you can access like
and later when you save
It will save just the tableA, but not the nested TableB
Note also that i used named queries as opposed to building the query
string in the code. Unless there is a good reason, like a complete free form dynamic query, I have found it better to use named queries as they are validated when hibernate boots up, as opposed to when they are run, which saves a lot of sanity when you are investigating a mature app and someone changed the table name but missed the one screen that was doing the query in the code using the old column name.
The other thing i did differntly was use the hibernate query as opposed to the sql query. Again unless there is a good reason to use sql queries, like adhoc join of different tables, it is better to use hibernate mappings and hibernate queries.
[ July 03, 2006: Message edited by: Travis Hein ]