Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.7
Mapping documents:
Child Mapping
<?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>
Parents Mapping
<?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">
<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>
<?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.Funcionario" table="FUNCIONARIOS" >
<id name="id" column="FUNCIONARIO_ID" unsaved-value="0">
<generator class="increment" />
</id>
<property name="matricula" column="MATRICULA" not-null="true" />
<property name="cargo" column="CARGO" not-null="true"/>
<property name="nome" column="NOME" not-null="true"/>
<property name="telefone" column="TELEFONE" not-null="true"/>
<property name="email" column="EMAIL" not-null="true"/>
<set name="ligacoes" lazy="true" inverse="true" cascade="all">
<key column="FUNCIONARIO_ID"/>
<one-to-many class="hello.Ligacao"/>
</set>
</class>
</hibernate-mapping>
<?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.Pessoa" table="PESSOAS" >
<id name="id" column="PESSOA_ID" >
<generator class="increment" />
</id>
<property name="nome" column="NOME" />
<property name="telefone" column="TELEFONE" />
<property name="celular" column="CELULAR" />
<set name="pessoasDestinadas"
lazy="true"
cascade="all"
inverse="true">
<key column ="PESSOA_ID"/>
<one-to-many class="hello.PessoaDestinada"/>
</set>
<set name="ligacoes" lazy="true" inverse="true" cascade="all">
<key column="PESSOA_ID"/>
<one-to-many class="hello.Ligacao"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Here is the point .
I get from an internet session the 3 full parent objects already persisted, so they are detached objects.
I build a new Ligacao (PhoneCall) and add the 3 parents
destino.addLigacao();
funcionario.addLigacao();
pessoa.addLigacao();
and i get
- one insert
insert into LIGACOES (DATAHORA, MOTIVO, NUMERO, DURACAO, DESTINO_ID, PESSOA_ID, FUNCIONARIO_ID, LIGACAO_ID) values (?, ?, ?, ?, ?, ?, ?, ?)
- 3 updates
update DESTINOS set NOME=?, ENDERECO=?, PAIS=?, TELEFONECENTRAL=? where DESTINO_ID=?
update PESSOAS set NOME=?, TELEFONE=?, CELULAR=? where PESSOA_ID=?
update FUNCIONARIOS set MATRICULA=?, CARGO=?, NOME=?, TELEFONE=?, EMAIL=? where FUNCIONARIO_ID=?
but i do not want to update that 3 parents.
So what could i do ?!
The other way i tried was ..
s.get(Destino.class,destino.getId());
s.get(Funcionario.class,funcionario.getId());
s.get(Pessoa.class,pessoa.getId());
destino.addLigacao();
pessoa.addLigacao();
funcionario.addLigacao();
to ensure that the objects still exist on database.
That does six selects !! and if i try to lock , Hibernate says that has an object that is dirty and do not complete the operation.
Hibernate: select destino0_.DESTINO_ID as DESTINO_ID0_, destino0_.NOME as NOME0_, destino0_.ENDERECO as ENDERECO0_, destino0_.PAIS as PAIS0_, destino0_.TELEFONECENTRAL as TELEFONE5_0_ from DESTINOS destino0_ where destino0_.DESTINO_ID=?
Hibernate: select pessoa0_.PESSOA_ID as PESSOA_ID0_, pessoa0_.NOME as NOME0_, pessoa0_.TELEFONE as TELEFONE0_, pessoa0_.CELULAR as CELULAR0_ from PESSOAS pessoa0_ where pessoa0_.PESSOA_ID=?
Hibernate: select funcionari0_.FUNCIONARIO_ID as FUNCIONA1_0_, funcionari0_.MATRICULA as MATRICULA0_, funcionari0_.CARGO as CARGO0_, funcionari0_.NOME as NOME0_, funcionari0_.TELEFONE as TELEFONE0_, funcionari0_.EMAIL as EMAIL0_ from FUNCIONARIOS funcionari0_ where funcionari0_.FUNCIONARIO_ID=?
Hibernate: select ligacoes0_.DESTINO_ID as DESTINO_ID__, ligacoes0_.LIGACAO_ID as LIGACAO_ID__, ligacoes0_.LIGACAO_ID as LIGACAO_ID2_, ligacoes0_.DATAHORA as DATAHORA2_, ligacoes0_.MOTIVO as MOTIVO2_, ligacoes0_.NUMERO as NUMERO2_, ligacoes0_.DURACAO as DURACAO2_, ligacoes0_.DESTINO_ID as DESTINO_ID2_, ligacoes0_.PESSOA_ID as PESSOA_ID2_, ligacoes0_.FUNCIONARIO_ID as FUNCIONA8_2_, pessoa1_.PESSOA_ID as PESSOA_ID0_, pessoa1_.NOME as NOME0_, pessoa1_.TELEFONE as TELEFONE0_, pessoa1_.CELULAR as CELULAR0_, funcionari2_.FUNCIONARIO_ID as FUNCIONA1_1_, funcionari2_.MATRICULA as MATRICULA1_, funcionari2_.CARGO as CARGO1_, funcionari2_.NOME as NOME1_, funcionari2_.TELEFONE as TELEFONE1_, funcionari2_.EMAIL as EMAIL1_ from LIGACOES ligacoes0_ left outer join PESSOAS pessoa1_ on ligacoes0_.PESSOA_ID=pessoa1_.PESSOA_ID left outer join FUNCIONARIOS funcionari2_ on ligacoes0_.FUNCIONARIO_ID=funcionari2_.FUNCIONARIO_ID where ligacoes0_.DESTINO_ID=?
Hibernate: select ligacoes0_.PESSOA_ID as PESSOA_ID__, ligacoes0_.LIGACAO_ID as LIGACAO_ID__, ligacoes0_.LIGACAO_ID as LIGACAO_ID1_, ligacoes0_.DATAHORA as DATAHORA1_, ligacoes0_.MOTIVO as MOTIVO1_, ligacoes0_.NUMERO as NUMERO1_, ligacoes0_.DURACAO as DURACAO1_, ligacoes0_.DESTINO_ID as DESTINO_ID1_, ligacoes0_.PESSOA_ID as PESSOA_ID1_, ligacoes0_.FUNCIONARIO_ID as FUNCIONA8_1_, funcionari1_.FUNCIONARIO_ID as FUNCIONA1_0_, funcionari1_.MATRICULA as MATRICULA0_, funcionari1_.CARGO as CARGO0_, funcionari1_.NOME as NOME0_, funcionari1_.TELEFONE as TELEFONE0_, funcionari1_.EMAIL as EMAIL0_ from LIGACOES ligacoes0_ left outer join FUNCIONARIOS funcionari1_ on ligacoes0_.FUNCIONARIO_ID=funcionari1_.FUNCIONARIO_ID where ligacoes0_.PESSOA_ID=?
Hibernate: select ligacoes0_.FUNCIONARIO_ID as FUNCIONA8___, ligacoes0_.LIGACAO_ID as LIGACAO_ID__, ligacoes0_.LIGACAO_ID as LIGACAO_ID1_, ligacoes0_.DATAHORA as DATAHORA1_, ligacoes0_.MOTIVO as MOTIVO1_, ligacoes0_.NUMERO as NUMERO1_, ligacoes0_.DURACAO as DURACAO1_, ligacoes0_.DESTINO_ID as DESTINO_ID1_, ligacoes0_.PESSOA_ID as PESSOA_ID1_, ligacoes0_.FUNCIONARIO_ID as FUNCIONA8_1_, pessoa1_.PESSOA_ID as PESSOA_ID0_, pessoa1_.NOME as NOME0_, pessoa1_.TELEFONE as TELEFONE0_, pessoa1_.CELULAR as CELULAR0_ from LIGACOES ligacoes0_ left outer join PESSOAS pessoa1_ on ligacoes0_.PESSOA_ID=pessoa1_.PESSOA_ID where ligacoes0_.FUNCIONARIO_ID=?
Hibernate: insert into LIGACOES (DATAHORA, MOTIVO, NUMERO, DURACAO, DESTINO_ID, PESSOA_ID, FUNCIONARIO_ID, LIGACAO_ID) values (?, ?, ?, ?, ?, ?, ?, ?)
Thanks in advance ! and sorry by my english :)
Full stack trace of any exception that occurs:
Name and version of the database you are using:Sybase
The generated SQL (show_sql=true):