Forgive the newbie question. I've searched and searched and not found the answer I'm looking for. Or rather I've found several answers and none of them seem to work for my particular use case.
I am trying to map some TV show data from an existing website, with an existing java API into Hibernate.
There are some oddities to the data which I know how I would program around, but I feel sure that Hibernate should be able to cope with. I'll explain the models (reduced for simplicity's sake, but they can be found
HERE)
There are three classes I'm currently interested in:
Series (Holds info on the TV series)
Code:
public class Series {
private String id;
private String seriesName;
private List<Person> actors = new ArrayList<Person>();
// Getters & Setters
}
Episode (Holds information on individual episodes)
Code:
public class Episode {
private String id;
private int seasonNumber;
private int episodeNumber;
private String episodeName;
private List<String> directors = new ArrayList<String>();
private List<String> guestStars = new ArrayList<String>();
// Getters & setters
}
Person (Holds information on cast members, but I also want to add in directories, writers, etc)
Code:
public class Person implements Comparable<Person> {
private long id;
private String name;
private String job;
private String role;
// Getters & Setters
}
So the relationships are:
Series 1:M Episode (A Series has many Episode)
Series M:M Person (A Series can have many Person, a Person can be in many Series)
Episode M:M Person (An Episode can have many Person, a Person can be in many Episode)
Side note:I'd like to try and not create specific attributes of the models for Hibernate and use JPA if possible. I saw some solutions that advised adding a "List<Series> series" to each person, but that would not be possible to populate from the source site and would mean nothing to people who use the API without hibernate.
So, the first complication:Each series has a list of actors, they do have a UID with them, but that is specific to the site I'm gathering data from, so I'd like to create my own UID. So when I save the series record, I need to look that up and reference the existing record if there, otherwise it should be created.
Can this be done (easily?) using JPA?
I know how I would do it with code, but how do I maintain the relationship with the
Second complicationThe episode person information, held in the "directors" and "guestStars" fields, need to be merged into the Person table.
I can create the records easily, but how do I create the associate between the Episode and "new" Person record?
Is it a case of manually maintaining a "Episode_Person" table?
Thanks for any insight or pointers you might give to a newbie. I feel if I can crack this, the rest should fall into place.
Stuart