Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic