Hello,
(I have a feeling this has something to
http://hibernate.org/155.html and inverse="true/false", but would appreciate guidance with adding inverse='true/false" to the correct side of the relation)
Summary of the problem:
Saving one domain model POJO does not save (insert) another, required
domain model POJO.
Details:
2 tables: ACCOUNT & USER_INFO
2 domain model POJOs: Account & UserInfo
When saving UserInfo to USER_INFO table, no Account is inserted into
ACCOUNT table.
-- ACCOUNT:
id SERIAL
CONSTRAINT pk_account_id PRIMARY KEY,
username ....
-- USER_INFO:
id SERIAL
CONSTRAINT pk_user_info_id PRIMARY KEY ,
account_id INTEGER
CONSTRAINT fk_user_info_account_id REFERENCES account(id) ,
first_name ....
-- ACCOUNT.hbm.xml:
<one-to-one
name="userInfo"
class="com.example.model.UserInfo"
cascade="all"
outer-join="auto"
constrained="false"
property-ref="account"
/>
-- USERINFO.hbm.xml:
<many-to-one
name="account"
class="com.example.model.Account"
column="account_id"
not-null="true"
unique="true"
/>
-- JAVA CODE that does not 'do the right thing':
Account acct = getAccountFromSomewhere();
UserInfo uinfo = new UserInfo("John", ....);
uinfo.setAccount(acct);
// IMPORTANT: if I add the following line, then Account IS saved
// acct.setUserInfo(uinfo);
Session ses = getHibernateSessionFromSomewhere();
ses.save(uinfo);
ses.flush();
ses.connection().commit();
ses.close();
Thank you,
Otis