Hello!
I need help implementing the following relationship. I have the following DB structure:
CREATE TABLE rate_cards
(
rate_card_id NUMBER NOT NULL (primary key)
rate_card_name
rate_card_percentage
change_date
)
CREATE TABLE advertiser_rate_cards
(
rate_card_id FK to rate_cards,
advertiser_id FK to advertiser_v,
change_date
)
CREATE OR REPLACE VIEW advertisers_v (
advertiser_id,
advertiser_name )
........
)
Advertiser can belong to many rate cards. And rate card can be assigned to multiple advertisers.
My POJO has the following desing:
public class RateCard {
private int id;
private String name;
private int percentage;
private Date changeDate;
private List<Advertiser> selectedAdvertisers;
}
public class Advertiser {
private int id;
private String name;
When retrieving a rate card, I would also like to get a list of advertisers assigned to it. Can you please explain to me how I should go about mapping these two objects to achieve desired results?
I would like to avoid creating a separate class for the relationship table advertiser_rate_cards as it does not make sense from the OO design. As this is not a single case, I would end up with a lot of classes that represent db relationships and i would like to avoid that.
So far, we have been using regular JDBC calls to retrieve assigned collections. So, RateCard is mapped using hibernate. All properties of the java class are mapped except for selectedAdvertisers. Once the object is retrieved using
(RateCard)HibernateUtil.getStandard().getBusinessObject(RateCard.class,
new Integer(rateCardId))
I execute a separate method getSelectedAdvertisers(rateCardId) inside which i execute a regular jdbc query "select id, name from advertiser_v adv, advertiser_rate_cards where rate_card_id = xxx and advertiser_id = adv.id"
I would like to use hibernate features to achieve the same. I've searched google and forums but I could not find any solutions or examples. It would be helpful if i can see some examples/code.
Thanks for the help. I would really really appreciate it.
Julia.
|