I am not able to get a <one-to-one> associated object to be NOT loaded together with the main object. In this regard <one-to-one> is different from <many-to-one> and <one-to-many>.
Hibernate version:
3.05
Mapping documents:
<hibernate-mapping>
<class name="com.exigen.test.hibernate.Table1" table="Table1">
<id name="id" column="id" type="integer">
<generator class="increment"/>
</id>
<property name="value" type="string"/>
<one-to-one name="link" class="com.exigen.test.hibernate.Table2" property-ref="link" access="field"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.exigen.test.hibernate.Table2" table="Table2">
<id name="id" column="id" type="integer">
<generator class="increment"/>
</id>
<property name="value" type="string"/>
<many-to-one name="link" class="com.exigen.test.hibernate.Table1" access="field" column="fk"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
System.out.println("==================================================");
Session s1 = (Session) TestHelper.getSession();
Table1 t = (Table1) s1.load(Table1.class, new Integer(1));
System.out.println(t.getValue());
System.out.println("==================================================");
Session s2 = (Session) TestHelper.getSession();
Criteria c = s2.createCriteria(Table1.class);
List l1 = c.list();
System.out.println("==================================================");
Session s3 = (Session) TestHelper.getSession();
Query q = s3.createQuery("from Table1");
List l2 = q.list();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Postgre SQL
The generated SQL (show_sql=true):
==================================================
Hibernate: select table1x0_.id as id6_0_, table1x0_.value as value6_0_ from Table1 table1x0_ where table1x0_.id=?
Hibernate: select table2x0_.id as id7_0_, table2x0_.value as value7_0_, table2x0_.fk as fk7_0_ from Table2 table2x0_ where table2x0_.fk=?
11111
==================================================
Hibernate: select this_.id as id6_0_, this_.value as value6_0_ from Table1 this_
Hibernate: select table2x0_.id as id7_0_, table2x0_.value as value7_0_, table2x0_.fk as fk7_0_ from Table2 table2x0_ where table2x0_.fk=?
==================================================
Hibernate: select table1x0_.id as id6_, table1x0_.value as value6_ from Table1 table1x0_
Hibernate: select table2x0_.id as id7_0_, table2x0_.value as value7_0_, table2x0_.fk as fk7_0_ from Table2 table2x0_ where table2x0_.fk=?
Debug level Hibernate log excerpt:
|