Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange Hibernate/foreign key problem

 
Lonnie Lewis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.




 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!