• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Open Session in View issues

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using Struts + Hibernate. I am using "save" action and forwarding to "edit" action which will show JSP page with recently saved record. I am using "lazy" fetching strategy. To avoid LazyInitializationException, I implemented HibernateFilter and HibernateUtil class as explained on hibernate.org.

In this scenario, I am getting an exception org.hibernate.ObjectNotFoundException: No row with the given identifier exists:

Because, data is not committed and another request "edit" is fired which tries to fetch record.

Can anybody guide me for better approach to handle transactions in such scenarios or alternative of Open Session View in Filter?

Thanks,
Bhavin
[ October 30, 2008: Message edited by: Bhavin Sanghani ]
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After you did your thing, did you "flush" ?
Btw, I am no expert, but I always use hibernate with Spring.
Spring takes care of everything for me.
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried that but the problem is to re-issuing the request and start new session from view, I think...so, transaction wil be committed and new session wil be started...
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your did not describe how you handle the transactions in your application just the session handling with your filter.

Should I imagine you try to save and read your data in the same transaction?

If so you can try to use one transaction to save your data and another transaction read it.
Your "save" action or business service below would do begin, save, commit.
Then your "display" action would search would search the newly created record.

Hope it will be helpful
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic