Hibernate @EmbeddedId + beitreten

Ich habe ein Mapping-Problem im Ruhezustand. Ich habe die folgenden zwei DB-Tabellen (ich darf die DB nicht ändern):

LOCATIONS {
   ID, -- PK
   NAME
}

LOCATION_GROUPS {
   LOC_ID, -- PK, and FK to LOCATIONS.ID
   GROUP_NAME -- PK
}

Ich habe versucht, Entitäten für diese DB-Tabellen zu erstellen, aber ich weiß nicht, wie ich die Verbindung zwischen den Tabellen abbilden soll. Hier ist mein Versuch (aber er ist falsch):

@Embeddable
public class LocationGroupId implements Serializable {

    private static final long serialVersionUID = -6437671620548733621L;
    private Location loc;  
    private String group;   

    @Column(name = "LOC_ID")
    public Location getLoc() {
        return loc;
    }

    @Column(name = "GROUP_NAME")
    public String getGroup() {
        return group;
    }

    // ...
}   

@Entity
@Table(name = "LOCATION_GROUPS")
public class LocationGroup {

    private LocationGroupId id;

    @EmbeddedId
    public LocationGroupId getId() {
        return id;
    }

    // ...
}


@Entity
@Table(name = "LOCATIONS")
public class Location {

    private Long id;
    private String name;
    private List<LocationGroup> groups;

    @Column(name = "NAME")
    public String getName() {
        return this.name;
    }

    @OneToMany(mappedBy = "id.loc")
    public List<LocationGroup> getGroups() {
        return this.groups;
    }

    @Id
    @Column(name = "ID")
    @SequenceGenerator(name = "LocationIdGen", sequenceName = "LOCATION_SQ")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "LocationIdGen")
    public Long getId() {
        return this.id;
    }

    // ...
}

Die Schwierigkeit ist, dass ich eine OneToMany-Verbindung zwischen einer Spalte und einem Teil einer embeddedId-Spalte herstellen möchte. Irgendeine Idee zu diesem Problem? (Ich verwende den Ruhezustand 4.0.1)

Antworten auf die Frage(1)

Ihre Antwort auf die Frage