
Untitled
By: a guest on
Jul 17th, 2012 | syntax:
None | size: 0.67 KB | hits: 11 | expires: Never
How should I implement this in Hibernate/ Spring?
public class Movie {
@Id
@GeneratedValue
private long id;
private String name;
@OneToMany(mappedBy = "id.movie")
private List<Rating> ratings
}
public class Rating {
@Embeddable
public static class RatingId {
@ManyToOne
@JoinColumn(name = "movieId")
private Movie movie;
@ManyToOne
@JoinColumn(name = "userId)
private User user;
// Equals and Hashcode which should check the associated tables @Ids
}
@EmbeddedId
private RatingId id;
private String comment;
private int rating;
}
public class User {
@Id
@GeneratedValue
private long id;
private String userName;
}