0

I hope this is the right place for this type of problem.

An Object of my class Movie can have several keywords ( like 'fight club', 'brad', 'fincher'), and be part of different categories (like 'Drama', 'Best Movies Ever') I implemented them as ManyToMany:

@OneToMany(targetEntity = Keyword.class,fetch=FetchType.EAGER)
    private Set<Keyword> keywords;

@OneToMany(targetEntity = MovieCategory.class, fetch=FetchType.EAGER)
    private Set<MovieCategory> movieCategories;

Somehow I don' think, this is not the correct relationshipmodel, how would you implement this? Right now hibernate wont allow me to fetch.eager. fetch.lazy is okay. I found this link http://www.mkyong.com/hibernate/hibernate-many-to-many-relationship-example-annotation/ but it didn't answered my question.

2
  • I'm not knowledgeable about Hibernate so can't help with your fetching, but many-to-many is absolutely how these things are related. Every movie can have multiple keywords and categories, and every keyword and category can apply to multiple movies. – Carson63000 May 12 '13 at 0:37
  • See ManyToMany bidirectional eager fetching. stackoverflow.com/questions/3978733/… – rwong May 12 '13 at 2:27
0

Why not use @ManyToMany? If different movies have different keywords and a keyword can be related to different movies then that requires @ManyToMany. The same goes for categories.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.