• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate: Does not refresh after deletion

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there. I have a parent and child relationship. If I delete the child, it does not reflect immediately in the application. I need to log-out and log-in back to the system to see the actual result.

Here's the mapping in parent:
<set name="bookmarks" cascade="all" inverse="true">
<key column="member_id"/>
<one-to-many class="Bookmark"/>
</set>

No mapping is child since it`s a unidirectional.

Thank you in advance!
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any idea on this guys?

Thanks!
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your delete transaction gets commited?
How do you delete the child?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I need to log-out and log-in back to the system to see the actual result.


Is this a web application? Are you using any session scoped beans? Or alternatively, what scope soes your Hibernate sesion have? Is it per transaction?
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, I am using an Interceptor(Open Session in View)that, according to what I read, will automatically handle the session for me. It is not per transaction. To be honest, I am not very sure on how it operate, but it works. It's just there are some small issues like this.


Arun. Yes it is commited. This is the code.


Thank you so much for the help.
[ October 12, 2007: Message edited by: Erap Estrada ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Erap Estrada:
Paul, I am using an Interceptor(Open Session in View)that, according to what I read, will automatically handle the session for me. It is not per transaction. To be honest, I am not very sure on how it operate, but it works. It's just there are some small issues like this.


Arun. Yes it is commited. This is the code.


Thank you so much for the help.

[ October 12, 2007: Message edited by: Erap Estrada ]



OK, i fyou are using session in view then the "interceptor" needs to be the one to open the session start the transaction and commit it when it comes back. If you have commit in your code that is not the interceptor, then you aren't really following the Session in View pattern.

So a ServletFilter would have

open session
begin transaction
forward to the next filter or the Servlet itself
It returns from the filter chain and servlet
commit or rollback the transaction
close session.

Mark
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark. So these activities need to happen on every single transaction?

open session
begin transaction
forward to the next filter or the Servlet itself
It returns from the filter chain and servlet
commit or rollback the transaction
close session.



Isn't that resource extensive? Currently, the Interceptor does not close a session after each transaction.

Also, if I will close the connection for each, I will have some problem accessing lazily loaded objects.

My hibernate filter is similar to what hibernate website have:

http://www.hibernate.org/43.html

Thanks!

[ October 18, 2007: Message edited by: Erap Estrada ]
[ October 18, 2007: Message edited by: Erap Estrada ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, basically a Session and a Transaction are a one to one relationship with each other. By doing the approach I wrote, you will have access to the session in your JSP page to not get he lazy initialization exception. In between request and responses you can just simple have Hibernate drop the JDBC connection if need be for those wizard type pages. The design I wrote is taken from the Hibernate documentation. for the Session In view pattern, actually more like the Hibernate Wiki pages. I am not too original here.

Mark
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the link from my earlier post, the documentation says the need to open and close every transaction, but the code snippet does not mention any opening or closing of a session.

Can you direct me to another website?

I am really novice on this.

Thank you in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, but it does call session.flush() which has the same effect.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of:

Here's the mapping in parent:
<set name="bookmarks" cascade="all" inverse="true">
<key column="member_id"/>
<one-to-many class="Bookmark"/>
</set>



Try:


The inverse attribute usually indicates a bidirectional association and can have odd effects when included in unidirectional relationships.
[ October 20, 2007: Message edited by: David Madouros ]
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul. The sample code from this link does not have "session.flush()" either. http://www.hibernate.org/43.html

Everytime it passes thru filter, it does not close the connection. I did try to close it by simply invoking the session.close(), still it does not work. I completely used now the Open Session in View.

David, that does not solve the problem.

I am still confused why the sample code from Hibernate website itself does not show any closing of the session while it says, it has too.

Also, I tried to close the session from my DAO but I am getting a LazyInitializationException.

Thanks for the help guys.
[ October 22, 2007: Message edited by: Erap Estrada ]
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic