Forums Register Login
Strange Hibernate/foreign key problem
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?


Try adding

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.

I promise I will be the best, most loyal friend ever! All for this tiny ad:
Why should you try IntelliJ IDEA ?

This thread has been viewed 1023 times.

All times above are in ranch (not your local) time.
The current ranch time is
Aug 15, 2018 23:02:30.