I am trying to understand the annotations MapKey and MapKeyColumn and I have found them confusing. I was reading an article that made me even more confused (The specification section)
I have an entity with an int field and it is not the primary key:
public class Connections{
...
public final int getConnectionId() {
return this.connectionId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_StartpointTNA")
public final Endpoint getStartpoint() {
return this.startpoint;
}
...
}
and in the other side I have
public class Endpoint{
...
@OneToMany(mappedBy = "startpoint", fetch = FetchType.LAZY, cascade = { javax.persistence.CascadeType.REMOVE })
@MapKeyColumn(name = "connectionId")
public Map<Integer, Connections> getConnections() {
return this.connections;
}
....
}
I dont know really how to fix this. I keep getting: org.apache.openjpa.persistence.ArgumentException: “connections” declared that it is mapped by “startpoint”, but that is a not a field of the related type.
what is the proper way to map this?
As someone posted to the JIRA you opened, get rid of the
finalon your methods.From the JPA 2 spec: