Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How should I implement this in Hibernate/ Spring?
  2. public class Movie {
  3.  
  4.   @Id
  5.   @GeneratedValue
  6.   private long id;
  7.  
  8.   private String name;
  9.  
  10.   @OneToMany(mappedBy = "id.movie")
  11.   private List<Rating> ratings
  12.  
  13. }
  14.  
  15. public class Rating {
  16.  
  17.   @Embeddable
  18.   public static class RatingId {
  19.  
  20.   @ManyToOne
  21.   @JoinColumn(name = "movieId")
  22.   private Movie movie;
  23.  
  24.   @ManyToOne
  25.   @JoinColumn(name = "userId)
  26.   private User user;
  27.  
  28.  // Equals and Hashcode which should check the associated tables @Ids
  29.  
  30.   }
  31.  
  32.   @EmbeddedId
  33.   private RatingId id;
  34.  
  35.   private String comment;
  36.  
  37.   private int rating;
  38.  
  39. }
  40.  
  41. public class User {
  42.  
  43.   @Id
  44.   @GeneratedValue
  45.   private long id;
  46.  
  47.  
  48.   private String userName;
  49. }