-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Needed a <one-to-one> relation loaded only when access
PostPosted: Thu Oct 06, 2005 9:15 am 
Newbie

Joined: Tue May 24, 2005 11:49 am
Posts: 2
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.