This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Strange Hibernate/foreign key problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a strange foreign key problem. I'm allowing Hibernate to create my table structure based on my annotated classes. When using the following



The generated table includes:



I'm getting a foreign key: car_id -> person_car.id

I can't figure out why it is creating the creating a foreign key back to the PERSON_CAR table. If I provide the annotation:

There is more code in the application. What other annotations create foreign keys? What could I be doing wrong?

Thanks.




 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try adding

@JoinColumn(name="personcarId")
or the name might be personcar_id, I forget which Hibernate will generate.

Without the @JoinColumn Hibernate will create a join table between the two tables.

However, also looking at what was generated, isn't the car_id the FK field to the car table? Which actually looks correct to me.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic