Hi all,
I have got an (@Embeddable) entity (Address) with a FK to a fully flagged reference entity (Country). Everything is working ok, however I can see that before each insert into Address, a select on Country occurs as the following log demonstrates:
Hibernate:
/* get current state uk.co.jemos.persistence.domain.reference.Country */ select
country_.COUNTRY_ID
from
COUNTRY country_
where
country_.COUNTRY_ID=?
Hibernate:
/* insert uk.co.jemos.persistence.domain.user.User
*/ insert
into
USERS
(ADDRESS_LINE1, ADDRESS_LINE2, CITY, COUNTRY_ID, POSTCODE, COUNTY_STATE, `EMAIL`, `FULL_NAME`, `USERNAME`, VERSION_NBR)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
I guess this SQL occurs just to validate the FK right? E.g. that the country exists before inserting Address. Does this mean that the only way to get rid of the SELECT for each INSERT is to remove the FK? I wanted to use something like Session.load() where I just specify the country id and I'll tell HB to consider as if the country id was there, without a trip to the database, but I guess this wouldn't be optimal/supported?
Thanks & Regards,
M.