I'm an absolute hql newbie so bear with me...
How do I write a hql query to retrieve the parent object of a child object?
I've got an object/table TrackClass with a one-to-many relationship with Track. Knowing Track, I would like to get the parent TrackClass. Right now I'm resorting to SQL, but I'm sure it could be written more elgantly with a single hql statement.
string tcID = session.CreateSQLQuery("select trackclassid from track where trackid = " + t.TrackID).UniqueResult().ToString();
if (tcID != null)
{
trackclass = TrackClassDao.GetTrackClass(Convert.ToInt32(tcID), session);
}
The TrackClassDao.GetTrackClass method simply loads the TrackClass using the session after finding the correct TrackClassID with the SQL.
你应该有一个many-to-one
映射关系在田径类TrackClass属性。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.