You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Everton Agner <ev...@yahoo.com.br> on 2009/12/18 20:40:10 UTC

Hibernate session should be cleared/flushed between lifecycle methods?

Hi,

I had a weird situation here and I want to know if it's really a "bug" of tapestry hibernate integration or not. 

I have a Edit Page. In my onValidate() method, I have already
instantiated a "current" object (que object I'm editing), and I call a
BO method for validation. That method load a List of objects (the same
Type of current, and including itself), and does the validation.

So, In my onSuccess() method, I update my "current" object on Session. But, I get a:

  "a different object with the same identifier value was already associated with the session:..."

That's because on onValidate() method, I called a BO method that loaded
a List of objects (including the "current" object), and it was lost in
memory. So, hibernate can't update it's session data.

My way out of this was calling session.clear() and session.flush() after the BO validation method.

So, Tapestry should do that between lifecycle methods to avoid these
kind of Runtime issues? I don't think it's necessarily a Developer
matter (as a framework user).

Thanks,

Everton



      ____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com

Re: Hibernate session should be cleared/flushed between lifecycle methods?

Posted by Alessandro Bottoni <al...@gmail.com>.
Il 18/12/2009 20:57, Thiago H. de Paula Figueiredo ha scritto:
> Em Fri, 18 Dec 2009 17:40:10 -0200, Everton Agner
> <ev...@yahoo.com.br> escreveu:
>> So, In my onSuccess() method, I update my "current" object on Session.
>> But, I get a:
>>
>>   "a different object with the same identifier value was already
>> associated with the session:..."
> 
> Are you using Session.update()? Use Session.merge() instead. It should
> solve your problem.
> 

Googling around I discovered this HowTo that seems to be talking of this
same problem:

http://wiki.apache.org/tapestry/Tapestry5AvoidingDifferentObjectWithSameIDExceptions

HTH

-- 

Alessandro Bottoni
Website: http://www.alessandrobottoni.it/

"Which is more dangerous? TV guided missiles or TV guided families?"
     -- unknown


Re: Res: Hibernate session should be cleared/flushed between lifecycle methods?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 19 Dec 2009 16:58:10 -0200, Everton Agner  
<ev...@yahoo.com.br> escreveu:

>> Are you using Session.update()? Use Session.merge() instead. It should  
>> solve your problem.
>
> Yes I am, but this method (the one I call on tapestry code) is on a  
> "base" core code that my app uses, I can't change it.

Well, your core code isn't using what it should. In my Generic  
DAO-Hibernate package, I used update() and I tried many ways to avoid the  
"a different object with the same identifier value was already associated  
with the session:...". No one worked. Now my package uses merge(). JPA  
doesn't have an update() method, just merge().

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Res: Hibernate session should be cleared/flushed between lifecycle methods?

Posted by Everton Agner <ev...@yahoo.com.br>.
> Are you using Session.update()? Use Session.merge() instead. It should solve your problem.

Yes I am, but this method (the one I call on tapestry code) is on a "base" core code that my app uses, I can't change it.




________________________________
De: Thiago H. de Paula Figueiredo <th...@gmail.com>
Para: Tapestry users <us...@tapestry.apache.org>
Enviadas: Sexta-feira, 18 de Dezembro de 2009 17:57:08
Assunto: Re: Hibernate session should be cleared/flushed between lifecycle methods?

Em Fri, 18 Dec 2009 17:40:10 -0200, Everton Agner <ev...@yahoo.com.br> escreveu:

> Hi,

Hi!

> So, In my onSuccess() method, I update my "current" object on Session. But, I get a:
> 
>   "a different object with the same identifier value was already associated with the session:..."

Are you using Session.update()? Use Session.merge() instead. It should solve your problem.

--Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor
Owner, software architect and developer, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


      ____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com

Re: Hibernate session should be cleared/flushed between lifecycle methods?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 18 Dec 2009 17:40:10 -0200, Everton Agner  
<ev...@yahoo.com.br> escreveu:

> Hi,

Hi!

> So, In my onSuccess() method, I update my "current" object on Session.  
> But, I get a:
>
>   "a different object with the same identifier value was already  
> associated with the session:..."

Are you using Session.update()? Use Session.merge() instead. It should  
solve your problem.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Hibernate session should be cleared/flushed between lifecycle methods?

Posted by Taylor Mathewson <ta...@gmail.com>.
Rather than flushing and or clearing the full session, you can evict that
particular instance.

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#evict%28java.lang.Object%29

On Fri, Dec 18, 2009 at 2:40 PM, Everton Agner
<ev...@yahoo.com.br>wrote:

> Hi,
>
> I had a weird situation here and I want to know if it's really a "bug" of
> tapestry hibernate integration or not.
>
> I have a Edit Page. In my onValidate() method, I have already
> instantiated a "current" object (que object I'm editing), and I call a
> BO method for validation. That method load a List of objects (the same
> Type of current, and including itself), and does the validation.
>
> So, In my onSuccess() method, I update my "current" object on Session. But,
> I get a:
>
>  "a different object with the same identifier value was already associated
> with the session:..."
>
> That's because on onValidate() method, I called a BO method that loaded
> a List of objects (including the "current" object), and it was lost in
> memory. So, hibernate can't update it's session data.
>
> My way out of this was calling session.clear() and session.flush() after
> the BO validation method.
>
> So, Tapestry should do that between lifecycle methods to avoid these
> kind of Runtime issues? I don't think it's necessarily a Developer
> matter (as a framework user).
>
> Thanks,
>
> Everton
>
>
>
>
>  ____________________________________________________________________________________
> Veja quais são os assuntos do momento no Yahoo! +Buscados
> http://br.maisbuscados.yahoo.com
>