anthony wrote:
Quote:
Hi guys it is the third time that i try to be answered about that.
http://www.hibernate.org/ForumMailingli ... AskForHelpCode:
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.