I have two tables which have Many-to-Many relations which have a JoinTable USER_SERVICES as below.
@Entity
public class User implements Serializable {
@NotNull
@Column(unique=true)
private String username;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "USER_SERVICES",
joinColumns = {@JoinColumn(name = "id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "", referencedColumnName = "name")})
private Set<Services> services;
// Getters and Setters
}
@Entity
public class Services implements Serializable {
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private Long serviceId;
@NotNull
@Column(unique=true)
private String name;
//Getters and Setters
}
The above code creates a table USER_SERVICES, but I also want to have a Many-to-Many relation on the table USER_SERVICES with another table RATINGS which would result in another table USER_SERVICES_RATINGS. how can I define this relation with Hibernate/JPA annotations?