0

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 :

enter image description here

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?

Ayushi
  • 405
  • 1
  • 9
  • 19
  • 1
    If you generate entities from tables only the tables you are selecting are taken into account. Dependencies to tables which you have not selected are not taken into account and therefor they are not in the generated classes. – SubOptimal Sep 28 '15 at 10:12
  • Make sure the film_actor table has both columns set as primary keys before doing reverse engineering. – Kainsin Feb 25 '16 at 16:49

1 Answers1

0

If you are creating new tables which have relationships to already reverse-engineered entities, you need to have new tables and old ones selected to do a proper reverse engineer.

I also ran into the problem of tools in not able to create annotations for and . Turns out it was a case issue. All table names () were upper case, once I switched to lower case, all entities were generated properly.

ddev
  • 1
  • 1
  • 2