-->
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: This error is ok ?! (update between sessions)
PostPosted: Wed Jan 12, 2005 1:32 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Hi ,there i´m a new Hibernate user!

I have this error when i simulate a situation where i try to update an object Destino in PessoaDestinada on a second session.
Hibernate tries to find it on PessoaDestinada table.

There is another way to know if an object is still on database
not using locks nor update !?

Sorry by my english and thanks!





Hibernate version: 2.1.7c

Mapping documents:<?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"
cascade="all-delete-orphan"
inverse="true"
lazy="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>


<?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-delete-orphan"
inverse="true"
lazy="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 SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>


<class name="hello.PessoaDestinada"
table="PESSOASDESTINADAS"
lazy="true">

<composite-id name="id" class="hello.PessoaDestinada$Id"
unsaved-value="any">

<key-property name="destinoId"
column="DESTINO_ID"/>

<key-property name="pessoaId"
column="PESSOA_ID"
/>
</composite-id>

<many-to-one name="destino"
insert="false"
update="false"
not-null="true"
column="DESTINO_ID"/>

<many-to-one name="pessoa"
insert="false"
update="false"
not-null="true"
column="PESSOA_ID"/>

</class>

</hibernate-mapping>




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

Destino dt =(Destino) s.get(Destino.class,new Long(3));
tx.commit();
s.close();

PessoaDestinadaDAO pdd= new PessoaDestinadaDAO();
pdd.insertPessoaDestino(dt,pessoa);



public boolean insertPessoaDestino(Destino destino, Pessoa pessoa)
throws HibernateException {


Session s1 = sf.openSession();
List result = null;
Transaction tx = null;



try {

tx = s1.beginTransaction();


s1.update(destino);

if (pessoa.getId() == null) {
s1.save(pessoa);

}


if (destino.getId() == null) {
s1.save(destino);

}


System.out.println(pessoa.getId());
System.out.println(destino.getId());



PessoaDestinada pd = new PessoaDestinada(destino,pessoa);


s1.save(pd);


tx.commit();

return true; ...........



Full stack trace of any exception that occurs:
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=?
78
3
Hibernate: select pessoasdes0_.DESTINO_ID as DESTINO_ID__, pessoasdes0_.PESSOA_ID as PESSOA_ID__, pessoasdes0_.DESTINO_ID as DESTINO_ID1_, pessoasdes0_.PESSOA_ID as PESSOA_ID1_, pessoa1_.PESSOA_ID as PESSOA_ID0_, pessoa1_.NOME as NOME0_, pessoa1_.TELEFONE as TELEFONE0_, pessoa1_.CELULAR as CELULAR0_ from PESSOASDESTINADAS pessoasdes0_ left outer join PESSOAS pessoa1_ on pessoasdes0_.PESSOA_ID=pessoa1_.PESSOA_ID where pessoasdes0_.DESTINO_ID=?
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)
at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:84)
at net.sf.hibernate.collection.Set.add(Set.java:154)
at hello.PessoaDestinada.<init>(PessoaDestinada.java:105)
at hello.PessoaDestinadaDAO.insertPessoaDestino(PessoaDestinadaDAO.java:126)
at hello.Runner.main(Runner.java:382)
Caused by: net.sf.hibernate.PropertyAccessException: Exception occurred inside setter of hello.PessoaDestinada.destino
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:49)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:230)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2223)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:315)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:288)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3303)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 16 more
Caused by: net.sf.hibernate.LazyInitializationException: cannot access loading collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:84)
at net.sf.hibernate.collection.Set.add(Set.java:154)
at hello.PessoaDestinada.setDestino(PessoaDestinada.java:132)
... 21 more
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
Erro em PessoaDestinadaDAO -> insertPessoasDestino() não concluido!


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

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 3:42 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
please Help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 4:00 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
I found the problem

in PessoaDestinada.java i had

setDestino(Destino destino) { ....destino.getPessoasDestinadas().add(this);

this did the error.


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.