-->
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.  [ 9 posts ] 
Author Message
 Post subject: Bidirectional one-to-many with excessive SQL Queries
PostPosted: Mon Oct 10, 2005 2:52 pm 
Newbie

Joined: Mon Oct 10, 2005 2:42 pm
Posts: 5
Hi!

I am having a problem with this bidirectional association.

I have a table SolicitacaoDao(1) associated with AndamentoDao (n).

When I execute a simple load at an Object from SolicitacaoDao:

SolicitacaoDao sol = (SolicitacaoDao) s.load(SolicitacaoDao.class,
new Integer(1));
sol.getQtEstadio();

and call a simple property of SolicitacaoDao by his get method, Hibernate executes sql commands to load all AndamentoDao objects, and AndamentoDao´s children too.

Can Anybody help me please??


SolicitacaoDao.hbm.xml -------
...

<property name="qtEstadio" type="int">
<column name="qtEstadio" />
</property>

<set name="andamento" table="Andamento"
cascade="save-update" lazy="true">
<key column="idSolicitacao" />
<one-to-many
class="br.com.unimed.oncologia.andamento.dao.AndamentoDao" />
</set>

...
------------------------------------
AndamentoDao.hbm.xml ------

...

<many-to-one name="solicitacao"
class="br.com.unimed.oncologia.solicitacao.dao.SolicitacaoDao"
cascade="none" insert="true" update="true" not-null="true">
<column name="idSolicitacao"></column>
</many-to-one>
...

------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 4:17 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
have the children set to be loaded lazily.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 4:23 pm 
Newbie

Joined: Mon Oct 10, 2005 2:42 pm
Posts: 5
But it is lazy loaded, and they are all using proxies.

<set name="andamento" table="Andamento"
cascade="save-update" lazy="true">
<key column="idSolicitacao" />
<one-to-many
class="br.com.unimed.oncologia.andamento.dao.AndamentoDao" />
</set>

Any other idea?

Tanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 4:51 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
sorry, I didn't look at your mapping files before I posted. What hibernate version are you using?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 5:01 pm 
Newbie

Joined: Mon Oct 10, 2005 2:42 pm
Posts: 5
No problem!

I am using version 2.1.

Tanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 5:16 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
hrmmm. version 2.1 defaults everything to lazy="false". try also declaring lazy="true" at the class level in your hbm file if not already done so

Code:
<class
    name="package.class"
    table="some_table"
    lazy="true"
>

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 5:21 pm 
Newbie

Joined: Mon Oct 10, 2005 2:42 pm
Posts: 5
Hello!

They are all lazyed and proxyed!

proxy="br.com.unimed.oncologia.solicitacao.dao.SolicitacaoDao"
lazy="true"

Tanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 9:30 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
well, I'm sorry but I cannot see any reason as to why hibernate is loading all that extra stuff :(

My experience is with the same settings is usually successful.

maybe it was a bug in version 2.1.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 3:27 pm 
Newbie

Joined: Mon Oct 10, 2005 2:42 pm
Posts: 5
I dont know either!

I all my cases in this Application when I use a bidirectional one-to-many/many-to-one association, when I load the objetc all it´s son´s are loaded too. And I´ve already seted everything as lay=true and all proxyed.

Somebody please help me!


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

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.