I am using Jboss hibernate tools plugin with Eclipse Kepler and JDK 6 to reverse engineer annotated POJO files from Mysql good old sakila db.
The hibernate code generation configuration is set to Generate EJB3 annotations . Below is the snippet of the database diagram :
It has a table film_actor which is used to support a many-to-many relationship between tables film and actor.
When i reverse engineer POJO from the tables film, actor & film_actor all together, i get:
Film.java
@Entity
@Table(name = "film", catalog = "sakila")
public class Film implements java.io.Serializable {
private Short filmId;
private String title;
private String description;
private Date releaseYear;
private byte languageId;
private Byte originalLanguageId;
private byte rentalDuration;
private BigDecimal rentalRate;
private Short length;
private BigDecimal replacementCost;
private String rating;
private String specialFeatures;
private Date lastUpdate;
private Set filmActors = new HashSet(0);
Actor.java
@Entity
@Table(name = "actor", catalog = "sakila")
public class Actor implements java.io.Serializable {
private Short actorId;
private String firstName;
private String lastName;
private Date lastUpdate;
private Integer age;
private Set filmActors = new HashSet(0);
FilmActor.java
@Entity
@Table(name = "film_actor", catalog = "sakila")
public class FilmActor implements java.io.Serializable {
private FilmActorId id;
private Actor actor;
private Film film;
private Date lastUpdate;
FilmActorId.java
@Embeddable
public class FilmActorId implements java.io.Serializable {
private short actorId;
private short filmId;
So far, So good. But if i already have POJOs generated for actor & film and i reverse engineer the table film_actor, i get the following class:
@Entity
@Table(name = "film_actor", catalog = "sakila")
public class FilmActor implements java.io.Serializable {
private FilmActorId id;
private Date lastUpdate;
Notice how the references for Actor & Film are missing if in this class as opposed to the previous FilmActor.java . Only if i regenerate POJOs for all the three tables together do i get the references for Actor & Film in FilmActor.java.
I am pretty new to hibernate, so i need a few clarifications :
1) Do we actually need references of Actor & Film in FilmActor.java? Is it a standard practice to have references of the classes to which it refers to using foreign key?
2) Why are the references missing in FilmActor.java if i reverse engineer this class seperately when i already have Actor.Java & Film.Java available in the same package? Is there any configuration setting for the same?