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

Problems with Hibernate and Lazy

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm completely new to Hibernate so probably I won't be able to explain my problem quite clearly, but I'll try.

I'm developing a webpage with jsp, and I'm using Hibernate + DAO pattern to implement the persistence of the site.

Everything is working fine, I can create, and update objects on most of my pages, but on some, where I need to get a little more dirty I'm finding some problems.

The thing is that I have objects, and users. And I have a relation table to join these two, so a user can have multiple objects, and an object can belong to lots of users. So on my object class, I have a collection of the users that have that object.

The problem is that in a page I want to add a user to the object collection, so I get the user and the object using my DAO, and then when I try to access the object's user Collection I get a Lazy error. I know that is because I have the lazy parameter off on my Hibernate configuration, but that's the way I want it to be.

I've read some things about "open in view" in Hibernate, but I don't quite understand how to implement that. I believe this is the correct way to do it, but I can't manage to implement it right.

So I would have 2 main questions:

1 - Does it sound like I'm doing things right, or you would suggest me to face the problem another way? (this means if it makes any sense what I explain above)

2 - Can anyone explain me how to solve the lazy error without changing the lazy value?

Thanks so much.
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to implement open session in view servlet filter. You can find an example at www.hibernate.org.
I think thats the only way to solve this issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic