Can I bypass an intermediate object in hibernate
I have top level entities TRACK, MEDIA_GROUP and MEDIA, each with an integer primary key. I also have a join table from TRACK to MEDIA_GROUP which is 1:1 and MEDIA has a FK column into MEDIA_GROUP. I'm trying to find a way in hibernate to map a collection of Media directly into the Track object, bypassing the creation of a MediaGroup object.
Basically I want to turn this:
TRACK <-> MEDIA_TRACK_MAP <-> MEDIA_GROUP <-> MEDIA
into this:
TRACK <-> MEDIA_TRACK_MAP <-> MEDIA
But the join开发者_运维知识库 column between MEDIA_TRACK_MAP and MEDIA isn't the primary key of MEDIA.
So, the answer here is 'No' unless you're willing to do some hacks by mapping SQL queries instead of tables. The only other alternative is to create a view that performs the join.
精彩评论