-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Collection without foreign key
PostPosted: Sun May 09, 2010 9:02 am 
Newbie

Joined: Wed Aug 29, 2007 8:43 am
Posts: 5
Location: Philahttps://forum.hibernate.org/ucp.php?i=profile&mode=reg_detailsdelphia, PA
I want to add a Collection of persistent objects to a class where the collection returned is based on a column value in the collection table but is NOT based on any foreign key. For example, let's say we have the following persistent classes: 'Movie', 'TvShow', and 'AwardShow'. We want all movies to be fetched with the full set of potential award shows it could appear in, based on the logic that it can only be in movie award show (e.g. Oscars). This is a made up example, so please don't think too hard about this data model :)

Code:
public class Movie {
  private Integer movieId;
  private String name;
  private List<AwardShow> possibleMovieAwardShows;
}


Code:
public class TvShow {
  private Integer tvShowId;
  private String name;
  private List<AwardShow> possibleTvShowAwardShows;
}



Code:
public class AwardShow {
  private Integer awardShowId;
  private String name;
  private String type;
}


Here are the tables:
Code:
movie
--------
movie_id
name

tvshow
---------
tvshow_id
name

award_show
-------------
award_show_id
name
type


When fetching a Movie, I want to left join on the 'award_show' table 'using (award_show.type = 'movie')... i.e. without any join column from the Movie table. How do I achieve this via annotations in the Movie class? I tried a bunch of different mappings, and none worked. Here were two I thought might achieve it:

Code:
@OneToMany(targetEntity = AwardShow.class, cascade = CascadeType.ALL)
@Column(name = "type")
@Formula(value = "'movie'")


Code:
@OneToMany(targetEntity = AwardShow.class, cascade = CascadeType.ALL)
@Where(clause = "type = 'movie'")


Any help would be really appreciated!

-Arthur Loder


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.