I am getting this infamous error:
Foreign key (FK69848D5097EB6FB4:DOCUMENT_HISTORY [VOTERDOC_ID])) must have same number of columns as the referenced primary key (VOTER_DOCUMENT [VOTER_ID,ID])
But I am not using a composite key. I've confirmed that in the database, the PK for both tables involved is the id field, which is VARCHAR. And here are my entities:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(name = "VOTER_DOCUMENT")
public class VoterDocument {
@Id
@Column(length = 45, name = "ID")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DOCTYPE_ID", nullable = false)
private DocumentType documentType;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "VOTER_ID", referencedColumnName = "ID", nullable = false)
private Voter voter;
@OneToMany(mappedBy = "voterDocument", fetch = FetchType.EAGER)
private final List<DocumentHistory> history =
new ArrayList<DocumentHistory>();
@OneToMany(mappedBy = "voterDocument", fetch = FetchType.EAGER)
private final List<VoterFile> files = new ArrayList<VoterFile>();
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(name = "DOCUMENT_HISTORY")
public class DocumentHistory {
@Id
@Column(length = 45, name = "ID")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "VOTERDOC_ID", referencedColumnName = "ID", nullable = false)
private VoterDocument voterDocument;
It seems to be a simple OneToMany mapping, but it's not working. But it's not working in the strangest way, telling me that VoterDocument has a composite primary key, which is not the case.
What could be the problem?
**UPDATED: I edited my original post to include the whole class, except for getters and setters (which have no markup or Annotations).
Mysteriously enough, the problem seems to have disappeared. I simply commented out the Annotations (in this class and in others), and the errors disappeared. Then I un-commented the comments, and it works!
I think there is some general funkiness going on here, not sure why.
Another error has popped up now, equally absurd. With a simple table:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(name = "ACTIVE_ELECTION")
public class ActiveElectionForCounty {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "COUNTY_ID")
private County county;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "ELECTION_EVENT_ID")
private ElectionEvent electionEvent;
This table's PK is the COUNTY_ID
field from the County table. And the error I am getting is:
MappingException: composite-id class must implement Serializable: ActiveElectionForCounty
Again with the composite key! But the table doesn't have a composite key! Nor did the last one! Its PK is the County FK. I don't see why Hibernate is complaining. Unfortunately, this time simply commenting and un-commenting the Annotations doesn't fix anything, which is normal of course.