• 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Entity manager: Hibernate generating wrong SQL (composite key of composite keys)

Ranch Hand
Posts: 106
Hibernate Python MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm using a table that has four columns as primary key, with pairs of two columns each referencing another table via composite FK (MySQL 5.1). Both references are identifying relationships, that is they are PK as well as FK in the PlayerStats table. The design can be viewed here:

Here's the stack trace (root cause):

The generated SQL is:

As you can see from the generated SQL, the first two columns in the SELECT are the names of the two composite primary key classes: "playerstat0_.score" and "playerstat0_.teamMember". They're also used in the WHERE clause for whatever reason. The code is obviously wrong. Can't say whether there's something wrong in my code or Hibernate.

Here's the Java code for the PlayerStat and PlayerStatId classes:

Note that I omitted the imports and the equals and hashCode methods. Note also this is supposed to be JPA 1.0 code. However I believe that doesn't matter much in terms of code generation.

In the servlet I simply call:

Can anyone tell what might go wrong?

Don't listen to Steve. Just read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!