JPA @JoinColumn issues while joining on non primary key columns
16,794
How can I make this work??
Normalize your database to use common PK-FK relationships. If needed - define composite PK.
Related videos on Youtube
Comments
-
Bhumir Jhaveri almost 2 years
I want to connect table based on one direction join, here is my code:
Class Person { @id String person_sk; int person_id; String Person_name; @OneToMany @joinColumn (name="person_reference_id") List<address> getAddresses() {} } class Address { @id int person_reference_id (referred from Person); @id int address_id; @id int phone_id; String street_name, zip_code; }
Now when I do getAddress, it does not work, because my join is based on person_ref_id and @id (primaryKey) column in Person class is person_sk.
If I use referencedColumn then also it doesn't work.
-
Bhumir Jhaveri almost 12 yearswell thats correct, but its really strange why framework is abandoning you to implement such odd situation.
-
Bhumir Jhaveri almost 12 yearsits true, but this cant be modified since its coming from certain external apps, but this is not appropriate functionality supported by jpa framework
-
Bhumir Jhaveri almost 12 yearsAll this is good when it's ideal scenario, but everytime one dont end up in getting ideal scenario and there are hardly any changes that can be applied to the data model.
-
d1e almost 12 yearsI think it is good they do not support such ridiculous stuff. It is just that if they were to workaround every feature concerning other layers, it would be over-engineered. Here is a workaround you can try stackoverflow.com/a/1506775/685962
-
cbmeeks over 8 yearsTelling someone to normalize their database does not work when you have legacy databases that actually pre-date Hibernate and contain millions upon millions of records and 15 years of legacy business logic running on dozens of servers.