I have a couple questions.
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.
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?
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.
-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]