Hello,
dusty wrote: > > > You don't have a @ManyToOne annotation on the InspectionPackage side. > Is that a JPA convention/default that it will just understand what you > want there? I have never tried that before. > > This is still a ManyToOne but instead of using a Join table it creates a Foreign key (idInspectionPackage) in the InpectionRequest table. I'm not sure where I found this solution to my problem ... either JPA or Hibernate docs. But it works for me. It is bi-directional. dusty wrote: > > > So you have a manager that is returning a Package and then you try to > iterate over the requests in the controller? The manager closes the > connection and so you get the initialization errors right? Or is this > happening in your view and can you run the OpenSessionInView filter? > > My manager is the InspectionRequest manager. I am returning a list of InspectionRequests. Each InspectionRequest may or may not have an InspectionPackage. When the List contains an InspectionRequest that has an InspectionPackage, I get the Lazy error. It happens in the Controller. I am not referencing the InspectionRequest's InspectionPackage ANYWHERE - not in the Controller, not in the jsp. And even if I were, I am most certainly not referencing the InspectionPackage's list of InspectionRequests, which are Lazily loaded ... dusty wrote: > > > If you always look at the Requests when you access a package then a > lazy collection is probably not the answer. If you are having > troubles with the N+1 performance with lots of data, then the second > level cache may be the answer. I have had success in caching child > collections for objects so there is no hit to the database. > > When I load an InspectionPackage I don't always need its List of InspectionRequests. That's why it's lazily loaded. What I don't get is WHAT this error even means. It does NOT mean that I am trying to reference a Collection that is lazily loaded and since the Session is closed it fails. It means ... something else, but I don't know what. At any rate, I am going to try to do a Hibernate.initialize() on the InspectionRequest's Collections, see if that works. It's not an optimal solution but I am curious to see if it 'fixes' the problem. If it does I'll have to look into a couple issues - Fetching strategies and as you mentioned, second-level cache. But I am not sure how to enable/use second-level cache with AppFuse ... Thanks for your response! Bob -D On Jun 12, 2008, at 7:16 AM, syg6 wrote: > > I can't figure out why I am getting this error. I recently changed > ALL my > Collections to LAZY because my application was just dragging when it > had a > lot of data. But this broke lots of stuff. I think I finally fixed > all the > stuff that broke (using Hibernate.initialize() to manually load > Collections > where necessary) but I have a couple pages that are still breaking. > > And the error isn't your typical 'failed to lazily load a > Collection' but > rather 'could not initialize proxy - no Session' Now as I understand > it this > means you are trying to access the Hibernate session (to load > something > that's not loaded, for example) and it's already closed. The error > occurs in > my Controller. > > Here are my classes: > > class InspectionRequest > { > private InspectionPackage inspectionPackage; > > @JoinColumn(name="idInspectionPackage", insertable=false, > updatable=false) > public InspectionPackage getInspectionPackage() > { > return inspectionPackage; > } > } > > class InspectionPackage > { > private Set<InspectionRequests> inspectionRequests; > > @OneToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, > fetch = > FetchType.LAZY) > @JoinColumn(name="idInspectionPackage") > public Set<InspectionRequest> getInspectionRequests() > { > return inspectionRequests; > } > } > > Whenever I try to load a list of InspectionRequests, if ANY of those > InspectionRequests has an InspectionPackage associated > (idInspectionPackage > != null) I get the LazyInitializationException, in the Controller, > not in > the page. If I debug and put a breakpoint in the Controller just > before > returning the List of InspectionRequests, and if I try to look at > the value > of the list, I get the LazyInitializationException. > > If, on the other hand, none of the InspectionRequests in the > returned List > have InspectionPackages associated it works fine. > > What the heck does this mean? While it's true that every > InspectionRequest > in the List will automagically load it's corresponding > InspectionPackage (if > it has one), the corresponding InspectionPackage's List of > InspectionRequests will NOT be loaded, as it is LAZY. But I am not > even sure > that that is the problem. > > What am I doing wrong? > > Bob > > -- > View this message in context: > http://www.nabble.com/Strange-LazyInitializationException%3A-could-not-initialize-proxy---no-Session-tp17801049s2369p17801049.html > Sent from the AppFuse - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Strange-LazyInitializationException%3A-could-not-initialize-proxy---no-Session-tp17801049s2369p17816833.html Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]