-->
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.  [ 5 posts ] 
Author Message
 Post subject: I can´t lock a detached object that a child was added !?
PostPosted: Thu Feb 03, 2005 9:41 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Hi guys it is the third time that i try to be answered about that.

I have 3 different and detached objects that comes fron an internet session and add a child for each.
like:

father.addChild(child) {

child.setFather..
father.getChilds.add ..

}

It generates

- One insert and three (in my case), unnecessary updates.
insert Child
update father
update father..

None Father table properties was modified !
Then when i lock, hibernate says that the object is dirty forcing me to update it.

There is a way to avoid this !?


Thanks in advance and sorry by english.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 9:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Hi guys it is the third time that i try to be answered about that.


http://www.hibernate.org/ForumMailingli ... AskForHelp
Code:
You are asking a favor. No-one has any responsibility to help you. You have not paid any money to use Hibernate. Nevertheless, the level of "free" support provided is far beyond what you could expect from most commercial software vendors.


Consider for-pay support
The Hibernate team (all of us) believe strongly in the JBoss Group model of "professional open source". We believe that for open source software to truly compete with commercial products, open source developers must be able to derive an income from their work. Already, revenues derived from commercial training, support and consulting services helps support the development of Hibernate.

We are absolutely committed to providing services that are true value for money; we strive to make Hibernate as easy to use as possible - nevertheless there are things we can communicate in-person that are simply very difficult to get across in documentation or the user forum.



tips: select-before-update, maybe dynamic-update too

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 11:30 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
anthony wrote:
Quote:
Hi guys it is the third time that i try to be answered about that.


http://www.hibernate.org/ForumMailingli ... AskForHelp
Code:
You are asking a favor. No-one has any responsibility to help you. You have not paid any money to use Hibernate. Nevertheless, the level of "free" support provided is far beyond what you could expect from most commercial software vendors.


Consider for-pay support
The Hibernate team (all of us) believe strongly in the JBoss Group model of "professional open source". We believe that for open source software to truly compete with commercial products, open source developers must be able to derive an income from their work. Already, revenues derived from commercial training, support and consulting services helps support the development of Hibernate.

We are absolutely committed to providing services that are true value for money; we strive to make Hibernate as easy to use as possible - nevertheless there are things we can communicate in-person that are simply very difficult to get across in documentation or the user forum.



tips: select-before-update, maybe dynamic-update too



Sorry, i thought that my explanation was enough clear.

That is the point, i am trying to avoid unnecessary queries, like that.
Where i do not change any properties to justify , these updates .
Just add a child to a parent , no other property is changed, so the same in the Parents table.
Here goes de xml´s , de objects , and DAO.
Hibernate 2.1.7.
Database Sybase.


One Parent
XML

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.Destino" lazy="true" table="DESTINOS" dynamic-update="true">
<id name="id" column="DESTINO_ID" >
<generator class="increment"/>
</id>
<property name="nome" column="NOME" not-null="true" />
<property name="endereco" column="ENDERECO" not-null="true"/>
<property name="pais" column="PAIS" not-null="true"/>
<property name="telefoneCentral" column="TELEFONECENTRAL" not-null="true"/>
<set name="pessoasDestinadas"
cascade="all"
lazy="true"
inverse="true"

>
<key column ="DESTINO_ID"/>
<one-to-many class="hello.PessoaDestinada"/>
</set>
<set name="ramais" lazy="true" inverse="true" cascade="all" >
<key column="DESTINO_ID"/>
<one-to-many class="hello.Ramal"/>
</set>
<set name="ligacoes" lazy="true" inverse="true" cascade="all">
<key column="DESTINO_ID"/>
<one-to-many class="hello.Ligacao"/>
</set>
</class>
</hibernate-mapping>



Child
XML


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.Ligacao" table="LIGACOES" lazy="true">
<id name="id" column="LIGACAO_ID" unsaved-value="any">
<generator class="increment" />
</id>
<property name="dataHora" column="DATAHORA" not-null="true"/>
<property name="motivo" column="MOTIVO" />
<property name="numero" column="NUMERO" not-null="true" />
<property name="duracao" column="DURACAO" not-null="true"/>

<many-to-one name="destino" column="DESTINO_ID" not-null="true"
class="hello.Destino"
update="false"
cascade="save-update"/>

<many-to-one name="pessoa" column="PESSOA_ID" not-null="true"
class="hello.Pessoa" cascade="save-update"/>

<many-to-one name="funcionario" column="FUNCIONARIO_ID" not-null="true"
class="hello.Funcionario" cascade="save-update"/>
</class>
</hibernate-mapping>



Code between session open/close

Ligacao ligacao= new Ligacao();

* Detached -> destino,funcionario,pessoa

destino.addLigacao(ligacao);
funcionario.addLigacao(ligacao);
pessoa.addLigacao(ligacao);

SQL

Hibernate: insert into LIGACOES (DATAHORA, MOTIVO, NUMERO, DURACAO, DESTINO_ID, PESSOA_ID, FUNCIONARIO_ID, LIGACAO_ID) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update DESTINOS set NOME=?, ENDERECO=?, PAIS=?, TELEFONECENTRAL=? where DESTINO_ID=?
Hibernate: update PESSOAS set NOME=?, TELEFONE=?, CELULAR=? where PESSOA_ID=?
Hibernate: update FUNCIONARIOS set MATRICULA=?, CARGO=?, NOME=?, TELEFONE=?, EMAIL=? where FUNCIONARIO_ID=?



I found in the forum that i cannot avoid these update, or other querie, just doing the insert. Is it right ?!

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 11:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Where i do not change any properties to justify , these updates .


do you know what does "detached" means?
it means that the session is no more able to detect any change.
So how do you think a re attachment is executed?
2 possibilities:
- make a select to be able to check both versions
- update all the graph

is it clear?

you should read hibernate in action

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 11:39 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Very clear , thank you very much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.