Hibernate version:
3.0.5
Mapping documents:
<class name="Country" table="COUNTRY" >
<id name="id" column="COUNTRYID"> </id>
<property name="name" column="NAME" />
</class>
<class name="City" table="CITY">
<id name="id" column="CITYID"></id>
<property name="name" column="NAME" />
<many-to-one class="Country" name="country" column="COUNTRYID"/>
</class>
Code between sessionFactory.openSession() and session.close():
Transaction transaction = session.beginTransaction();
// Country("US", "USA") is already in DB
City city = new City("WA", "Washington", new Country("US", null));
session.save(city);
transaction.commit();
Name and version of the database you are using:
HSQLDB 1.8.0.8
The generated SQL (show_sql=true):
Hibernate: select country_.COUNTRYID, country_.NAME as NAME1_ from COUNTRY country_ where country_.COUNTRYID=?
Hibernate: insert into CITY (NAME, COUNTRYID, CITYID) values (?, ?, ?)
Why does hibernate perform select query before insert query? How to configure it to perform only insert query?
Thanks for help!
|