Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Does not refresh after deletion

 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Any idea on this guys?

Thanks!
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your delete transaction gets commited?
How do you delete the child?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, but it does call session.flush() which has the same effect.
 
David Madouros
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic