Spring boot : Unique Constraint mit Many to Many

8u3631984

Bekanntes Mitglied
Hallo.
Ich habe folgende Entity :

Java:
@Entity
@Table(name = "samsCompetition", uniqueConstraints = @UniqueConstraint(columnNames = {"name", "association", "season"}))
public class SamsCompetition implements Competition {

    @NonNull
    private String name;

    @NonNull
    @Getter(AccessLevel.NONE)
    @ManyToOne
    private SamsAssociation association;

    @NonNull
    @Getter(AccessLevel.NONE)
    @ManyToOne
    private SamsSeason season;

Ich möchte nun über mehrere Spalten ein Unique Constraints erstellen. Wenn ich Spalten verwende - ohne ManyToOne Beziehung - klappt es ohne Probleme. In diesem Beisepil bekomme ich allerdings folgenden Fehler :

Code:
Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unable to create unique key constraint (name, association, season) on table sams_competition: database column 'association', 'season' not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)

Hat jemand einen Tipp für mich.
 
Definier mal die Join Coloumn explizit und gibt die oben an.

Siehe hier:

Das Problem ist, Das Constraint erwartet den Column Namen, du gibst aber den Attribut Namen an. Bei normalen Feldern kein Problem, aber bei Many To One wird ja eine Join-Column generiert und deren Namen musst du dann angeben.
 

Zurück
Oben