aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA: Map composite primary key with one field being foreign key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA: Map composite primary key with one field being foreign key" Watch "JPA: Map composite primary key with one field being foreign key" New topic
Author

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

David Karr
Greenhorn

Joined: Jan 06, 2008
Posts: 12
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA: Map composite primary key with one field being foreign key