Hello,
I work with the website “openfights.org” I import my data.
I have a persistence “MyApp”, 4 classes: Aireline, Airport, Route and RouteId. I use H2 as a database. I have an ImportData class to import my data from the openfights.org site.
When importing Aireline and Airport data are well filled.
the problem is that for the class Route I had to do a RouteId class because I have several primary keys.
Hibernate raises an exception on my RouteId class:
Could not set field value [410] value by reflection: [class flights.RouteId.airlineId] setter of >> flights.RouteId.airlineId
@EmbeddedId
private RouteId id;
private String airlineCode;
@ManyToOne // error : The type of the ID mapped by the relationship 'airline' does not agree with the primary key class of the target entity.
@MapsId("airlineId")
private Airline airline;
private String sourceCode;
@ManyToOne // error : The type of the ID mapped by the relationship 'source' does not agree with the primary key class of the target entity.
@MapsId("sourceId")
private Airport source;
private String destinationCode;
@ManyToOne // The type of the ID mapped by the relationship 'destination' does not agree with the primary key class of the target entity.
@MapsId("destinationId")
private Airport destination;
private Boolean codeshare;
private Short stops;
private String equipment;
public RouteId getId() {
return id;
}
public void setId(RouteId id) {
this.id = id;
}
public String getAirlineCode() {
return airlineCode;
}
public void setAirlineCode(String airlineCode) {
this.airlineCode = airlineCode;
}
public Airline getAirline() {
return airline;
}
public void setAirline(Airline airline) {
this.airline = airline;
}
public String getSourceCode() {
return sourceCode;
}
public void setSourceCode(String sourceCode) {
this.sourceCode = sourceCode;
}
public Airport getSource() {
return source;
}
public void setSource(Airport source) {
this.source = source;
}
public String getDestinationCode() {
return destinationCode;
}
public void setDestinationCode(String destinationCode) {
this.destinationCode = destinationCode;
}
public Airport getDestination() {
return destination;
}
public void setDestination(Airport destination) {
this.destination = destination;
}
public Boolean getCodeshare() {
return codeshare;
}
public void setCodeshare(Boolean codeshare) {
this.codeshare = codeshare;
}
public Short getStops() {
return stops;
}
public void setStops(Short stops) {
this.stops = stops;
}
public String getEquipment() {
return equipment;
}
public void setEquipment(String equipment) {
this.equipment = equipment;
}
@Embeddable // The Java class for mapped type “flights.RouteId” is final
public class RouteId implements Serializable {
private static final long serialVersionUID = -2403746842148223177L;
// assuming all Long ids
private int airlineId;
private int sourceId;
private int destinationId;
public int getAirlineId() {
return airlineId;
}
public void setAirlineId(int airlineId) {
this.airlineId = airlineId;
}
public int getSourceId() {
return sourceId;
}
public void setSourceId(int sourceId) {
this.sourceId = sourceId;
}
public int getDestinationId() {
return destinationId;
}
public void setDestinationId(int destinationId) {
this.destinationId = destinationId;
}
public static long getSerialversionuid() {
return serialVersionUID;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + airlineId;
result = prime * result + destinationId;
result = prime * result + sourceId;
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RouteId other = (RouteId) obj;
if (airlineId != other.airlineId)
return false;
if (destinationId != other.destinationId)
return false;
if (sourceId != other.sourceId)
return false;
return true;
}