Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

Posts: 12
  • Mark post as helpful
  • send pies
  • 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.
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic