-->
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.  [ 3 posts ] 
Author Message
 Post subject: Tries to select when I want to insert (help)
PostPosted: Fri Jan 28, 2005 2:22 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Hi guys, the relationship is One to many bidirectional

Destino -> Ligacoes
Pessoa -> Ligacoes
Funcionario-> Ligacoes

i am trying to persist a new Ligacao
(in english means "phonecall" or "call")
to a Destino(destiny), Pessoa(People) , Funcionario already persisted.

But it is selecting Ligacao opposite to Insert in sql LOG.

Thank you very much and sorry by english.



Hibernate version:2.1.7

Mapping documents:
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="none"
outer-join="false"/>

<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>


<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>


Funcionario and Pessoa have the same mapping of Destino basically

Code between sessionFactory.openSession() and session.close():

destino,funcionario,pessoa come from an internet session.

Destino destino=(Destino) s.get(Destino.class,destino.getId());
Pessoa pessoa= (Pessoa) s.get(Pessoa.class,pessoa.getId());
Funcionario funcionario=(Funcionario)s.get(Funcionario.class,funcionario.getId());




Ligacao ligacao = new Ligacao();
ligacao.setProperties..


method:
public void addLigacao(Ligacao ligacao) {
ligacao.setDestino(this);
this.ligacoes.add(ligacao);


}


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

Full stack trace of any exception that occurs:

Name and version of the database you are using:
SYBASE *

The generated SQL (show_sql=true):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 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 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=?
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 2:36 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
The other way that works, i construct the object
Ligacao in the internet session, and then i pass to method

s.save(ligacao) and it saves well, but updates the other destino,pessoa,funcionario objects.

Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 2:43 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Sorry i found the error in Ligacao class

public void setFuncionario(Funcionario funcionario) {
this.funcionario = funcionario;
//funcionario.getLigacoes().add(this);
}


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