Bo Vandersteene
Bo Vandersteene

Reputation: 639

@AssociationOverride and @joinColumn doesn't work

I have 2 classes who have both the District class, an existing database has these fk with a different name. I made a @AssociationOverride but get the error invalid column name district_arrondisid.

The class District

@Entity
@Table(name = "arrond")
@AttributeOverrides({ 
        @AttributeOverride(name = "id", column = @Column(name = "arrondisid")) 
})
public class District extends BasicString implements Comparable<District> {
}

The class BasicIDDistrict

@IdClass(BasicIDDistrictPK.class)
@MappedSuperclass
@XmlRootElement
public abstract class BasicIDDistrict {

    @Id
    private int id;

    @Id 
    @ManyToOne(fetch = FetchType.EAGER)
    @Fetch(FetchMode.JOIN)
    @JsonIgnore
    private District district;

    //getters and setters
}

The class one

@Entity
@Table(name = "tableA")
@AssociationOverrides({ 
        @AssociationOverride(name = "district", joinColumns =  
                        @JoinColumn(name = "arrondisid"))
})
@AttributeOverrides({ 
        @AttributeOverride(name = "id", column = 
                        @Column( name = "idA", insertable = false, updatable = false))
})
public class ClassA extends BasicIDDistrict {...}

The class one

@Entity
@Table(name = "tableB")
@AssociationOverrides({ 
        @AssociationOverride(name = "district", joinColumns = @JoinColumn(name = "id_arrond"))
})
@AttributeOverrides({ 
        @AttributeOverride(name = "id", column = @Column(name = "idB", insertable = false, updatable = false))
})
public class ClassB extends BasicIDDistrict {..}

Upvotes: 1

Views: 4974

Answers (1)

user1572828
user1572828

Reputation: 31

Don't know if you ever figured this but you should an empty @JoinColumn() on the district field in the base class so it has something to override.

Upvotes: 1

Related Questions