• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
  • Frits Walraven
  • fred rosenberger
  • salvin francis

JPA: Map composite primary key with one field being foreign key

Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble getting a mapping to work with Hibernate JPA, using Spring. I'll list several code excerpts, and the end of the note has the error message I'm getting.

I have two tables, "student" and "absence". the "absence" table has a composite primary key consisting of all of its columns, and one of those columns is also a foreign key to "student". They are defined somewhat like this in MySQL:

I'm attempting to map these with minimal annotations, specifying the mapping mostly in the orm.xml file.

The two classes, as I've defined them so far, are:

and then my orm.xml file (excerpt) is this, so far:

When I run a simple test, it fails to completely initialize, failing with this:

mappedBy reference an unknown target entity property: jpatest.domain.Absence.student in jpatest.domain.Student.absences

I also see the following warning appear before this failure:

Property jpatest.domain.Absence.student not found in class but described in <mapping-file/>

I'm not sure what I'm doing wrong here, but I'm sure it has something to do with the embedded id.

Besides pointing out what's "wrong", I'd appreciate any ideas of simpler ways to do this, although I'd prefer to continue using the XML descriptor more than annotations.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic