HI, I have the following model:
@Entity
class Flight{
private Airport airportFrom;
private Airport airportTo;
@OneToOne(fetch=FetchType.LAZY,optional=false)
public Airport getAirportFrom(){
return this.airportFrom;
}
@OneToOne(fetch=FetchType.LAZY,optional=false)
public Airport getAirportTo(){
return this.airportTo;
}
}
@Entity
class Airport{
private Integer airportId;
@Id
public Integer getAirportId(){
this.airportId;
}
}
And I'm getting this error:
org.hibernate.MappingException: Repeated column in mapping for entity: model.entities.Flight column: airportId (should be mapped with insert="false" update="false")
It's @JoinColumn you need, not @Column.
@OneToOne(fetch=FetchType.LAZY,optional=false)
@JoinColumn(name="airportFrom", referencedColumnName="airportId")
public Airport getAirportFrom(){
return this.airportFrom;
}
etc
(and as Frotthowe mentioned, it does seem a little bit odd for Flights to be OneToOne with airports. I must confess to usually ignoring the domain and assuming the names are some pseudo nonsense to facilitate the question :) )
@OneToOne
is wrong. It would mean that each Airport only has one Flight. Use @ManyToOne
. And you need to specify the column that references the from and to Airport id by @JoinColumn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With