I'm not sure if I get your question right, but do you mean something like this:
@IdClass(RoutePlacePK.class)
@Entity
public class RoutePlace {
private Collection<RoutePlace> route;
@ManyToMany(mappedBy = "place")
public Collection<RoutePlace> getRoute() {
return route;
}
public void setRoute(Collection<RoutePlace> route) {
this.route = route;
}
private Collection<RoutePlace> place;
@ManyToMany
public Collection<RoutePlace> getPlace() {
return place;
}
public void setPlace(Collection<RoutePlace> place) {
this.place = place;
}
}
The compound primary key wrapper class:
public class RoutePlacePK {
private int routeID;
private int placeID;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RoutePlacePK that = (RoutePlacePK) o;
if (placeID != that.placeID) return false;
if (routeID != that.routeID) return false;
return true;
}
public int hashCode() {
int result;
result = routeID;
result = 31 * result + placeID;
return result;
}
}