I generated my annotated code from an existing DB using the RevEng tool. I have a TblDetail table that has a composite primary key:
@Embeddable public class TblDetailId { String mission; String type; int num; }
I have a TblOrbit table that also has a composite primary key, with the same fields:
@Embeddable public class TblOrbitId { String mission; String type; int num; }
(It goes without saying that the corresponding table fields have the same names in the DB, and that I didn't make the DB and have little to no say in the structure.) The TblOrbit table has a foreign key onto the TblDetail table, so the RevEng tool generates:
public class TblDetail { TblOrbit orbit;
@OneToOne(fetch = FetchType.LAZY, mappedBy = "tblDetail") public TblOrbit getOrbit()... }
(Obviously, I left a lot out for brevity)
When I try to load a row from TblDetail, which is actually part of a one-to-many set from TblOverview, I get the exception:
org.hibernate.TypeMismatchException: Provided id of the wrong type for class TblOrbit. Expected: class TblOrbitId, got class TblDetailId
I have seen similar postings, but I just don't understand the problem or the solution. To make matters worse, there is ANOTHER table with a one-to-one with TblDetail, and it has, you guessed it, the same composite key structure.
I know this is the problem because I can comment out the one-to-one fields and my test case runs. Any help is appreciated.
Regards, reilly.
|