-->
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: one-to-one association on a primary key & N+1 sql
PostPosted: Fri Nov 18, 2005 6:56 am 
Newbie

Joined: Fri Nov 18, 2005 6:07 am
Posts: 1
Hi,

I want to use one-to-one association on a primary key between some tables but when I've checked what kind of sgl is produce I've noticed that records from associated table are read during accessing main table.

Some details:

Hibernate version: 3.0

Mapping documents:
MAIN TABLE
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="test.Main" table="MAIN">
<id name="idmain" type="integer">
<column name="IDMAIN" precision="9" scale="0" />
<generator class="identity" />
</id>
<property name="col2" type="string">
<column name="COL2" length="50" />
</property>
<one-to-one name="Table2" cascade="all"/>
</class>
</hibernate-mapping>

ASSOCIATED TABLE
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="test.Table2" table="TABLE_2" schema="dbo" catalog="RAPORTY">
<id name="idmain" column="IDMAIN">
<generator class="foreign">
<param name="property">main</param>
</generator>
</id>
<one-to-one name="main" class="test.Main" constrained="true"/>
<property name="column2" type="string">
<column name="COLUMN_2" length="10" />
</property>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Transaction tx = sesja.beginTransaction();
try {
obj = sesja.createQuery(coWybrac).list();
tx.commit();
}
catch(HibernateException hi1){
tx.rollback();
throw hi1;
}


Name and version of the database you are using: MS SQL

The generated SQL (show_sql=true):
Hibernate: select main0_.IDMAIN as IDMAIN, main0_.COL2 as COL2_1_ from RAPORTY.dbo.MAIN main0_
Hibernate: select table2x0_.IDMAIN as IDMAIN0_, table2x0_.COLUMN_2 as COLUMN2_0_0_ from RAPORTY.dbo.TABLE_2 table2x0_ where table2x0_.IDMAIN=?
Hibernate: select table2x0_.IDMAIN as IDMAIN0_, table2x0_.COLUMN_2 as COLUMN2_0_0_ from RAPORTY.dbo.TABLE_2 table2x0_ where table2x0_.IDMAIN=?
Hibernate: select table2x0_.IDMAIN as IDMAIN0_, table2x0_.COLUMN_2 as COLUMN2_0_0_ from RAPORTY.dbo.TABLE_2 table2x0_ where table2x0_.IDMAIN=?
Hibernate: select table2x0_.IDMAIN as IDMAIN0_, table2x0_.COLUMN_2 as COLUMN2_0_0_ from RAPORTY.dbo.TABLE_2 table2x0_ where table2x0_.IDMAIN=?


My relation between this table is exactly 1-0..1.
I have tried some lazy & fetch option but still have the same sqls. I don't want to use association on a foreign key because I want to add new associated table without changing on main table.

Is this situation normal for this kind of association or I should use some others options - if yes which one?

Thanks,


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.