java - Hibernate @JoinColumnOrFormula error -
i trying map entity through jointable, didn't work trying use @joincolumnorformula annotation, keep getting error. models user
, house
, userhousemap
. want use user.name
(non-primary key & non-unique) retrieve record user_house_map
using user_house_map.user_name
(primary key) & retrieve associated house
using other key house_name
, should reference house.house_name
(primary key)
the db structure weird, necessary & cannot changed @ point.
here have tried. may incorrect since theres no proper documentation on how use joincolumnorformula
@id @generatedvalue @expose public long id; @expose @required @manytoone @joincolumnsorformulas({ @joincolumnorformula(formula=@joinformula(value="(select user_name name user_housing_map user_name = name)", referencedcolumnname="house_name")), @joincolumnorformula(column = @joincolumn(name="house_name", referencedcolumnname="house_name")) }) public house house;
note: intially tried following mapping
@manytoone @jointable( name="user_house_map", joincolumns= @joincolumn(name="user_name", referencedcolumnname="name"), inversejoincolumns= @joincolumn(name="house_name", referencedcolumnname="house_name")) public house house;
but got error
unable find column logical name: name in org.hibernate.mapping.table(users)
here db schemas 3 models
users
table "public.users" column | type | modifiers -----------------------+-----------------------------+----------------------------- name | character varying(255) | id | integer | not null indexes: "user_pkey" primary key, btree (id) foreign-key constraints: "housing_fkey" foreign key (name) references user_house_map(user_name) deferrable deferred
houses
table "public.houses" column | type | modifiers ---------------+------------------------+----------- house_name | character varying(255) | not null address | text | city | text | state | text | zip | integer | zip_ext | integer | phone | text | indexes: "house_pkey" primary key, btree (house_name) referenced by: table "user_house_map" constraint "house_map_fkey" foreign key (house_name) references house(house_name) deferrable deferred
userhousemap
table "public.user_house_map" column | type | modifiers -------------+------------------------+----------- user_name | character varying(255) | not null house_name | character varying(255) | not null indexes: "user_house_map_pkey" primary key, btree (user_name) "user_house_map_house_key" btree (house_name) foreign-key constraints: "user_house_map_house_fkey" foreign key (house_name) references houses(house_name) deferrable deferred referenced by: table "users" constraint "housing_fkey" foreign key (name) references user_house_map(user_name) deferrable deferred
if user class then, should use jointable annotation referenced columns:
@manytoone @jointable( name="user_house_map", joincolumns= @joincolumn(name="user_name", referencedcolumnname="name"), inversejoincolumns= @joincolumn(name="house_name", referencedcolumnname="house_name")) public house house;
but joins not on @id column not supported jpa. luckily seems working hibernate.