Sure enough it was a hashCode issue.

In the stack trace I had the following line:

com.myco.myapp.model.Request.hashCode(Request.java:418)

When I went to my hashCode method it looked pretty normal:

return new HashCodeBuilder().append(code).append(type) ...

The offending line was:

append(inspectionPacket)

What could be wrong with InspectionPacket? I didn't know. I took it out of
Request's hashCode() method and everything worked. Hmmm ...

I went to take a look at Request and sure enough my ManyToOne mapping for
InspectionPacket was bad:

@ManyToOne(fetch = FetchType.LAZY)

I have no idea why I made it Lazy. It's the only Association in my entire
application mapped that way. All of my Associations (ManyToOne) are EAGER
and all of my Collections (OneToMany or ManyToMany) are LAZY.

Lesson learned. You get a Lazy Exception saying 'such-and-such a Collection
could not be loaded' when it's a problem with a lazily-loaded Collection.
Obviously. But when it's an Association, instead of saying 'Association
could not be loaded' it says 'no proxy'. Ok then.

I hope this helps someone, somewhere. It certainly cleared up a mystery for
me!

Bob
                

, just a bunch of 



syg6 wrote:
> 
> I posted a similar message a while back. I only got one response. I
> thought I had fixed my problem by eagerly loading my Object's Collections
> when needed. But no, it's broke again.
> 
> In summary, I am getting the famous 'could not initialize proxy - no
> Session' error when trying to display a list of Inspections. It started
> appearing after I made all of my Collections LAZY to make loading easier
> on the DB. 
> 
> The Object in question is Inspection and it has 2 Collections: infractions
> and residuos. NEITHER of these Collections are referenced in the list page
> so I should not be getting a Lazy Exception. In fact, this particular Lazy
> Exception is a mystery to me. It's not the typical 'Unable to load
> Collection' error that I would except if, for example, I tried to
> reference an Object's Collection if that Collection is lazily loaded.
> 
> In fact, the error does not occur in the page at all but rather in the
> Manager! I changed the Manager's code so it would eagerly load my two
> Collections. This seemed to work, I stopped getting the Lazy Exception
> error for a while. But it stopped working. This is the code:
> 
> public List<Inspection> findByStatus(Long idStatus)
> {
>   List<Inspection> inspections = getHibernateTemplate().find("from
> Inspection where inspeccionStatus.id = ?", idStatus);
>   ArrayList<Inspection> eagerInspections = new ArrayList<Inspection>();
>       
>   for (int i=0; i<inspections.size(); i++)
>   {
>     Inspection inspection = inspections.get(i);
>     inspection = getEager(inspection.getId());
>     eagerInspections.add(inspection);
>   }
>   
>   return eagerInspections;
> }
> 
> public Inspeccion getEager(Long id) 
> {
>     Inspection i = get(id);
>     Hibernate.initialize(i.getInfractions());
>     Hibernate.initialize(i.getResidues());
>     return i;
> }
> 
> As I said, this code seemed to do the trick. But all of a sudden it's
> broke again. I have no idea what the problem is. It seems the problem is
> NOT (and never has been) the Collections. Here is part of the stack trace.
> Is something wrong my my hashCode() methods?
> 
> 2008-07-09 10:44:45.694::WARN:  Nested in
> org.springframework.web.util.NestedServletException: Request processing
> failed; nested exception is org.hibernate.LazyInitializationException:
> could not initialize proxy - no Session:
> org.hibernate.LazyInitializationException: could not initialize proxy - no
> Session
>       at
> org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
>       at
> org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
>       at
> org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
>       at
> com.myco.myapp.model.InspectionPacket$$EnhancerByCGLIB$$fa7dc626.hashCode(<generated>)
>       at
> org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:856)
>       at com.myco.myapp.model.Request.hashCode(Request.java:418)
> 
>       at
> org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:856)
>       at com.myco.myapp.model.Inspection.hashCode(Inspeccion.java:419)
> 
> When I first changed from Eager to Lazy, many of my Objects broke because
> I had those Objects' Collections in the hashCode() and toString() methods.
> But not anymore. My Inspection Object DOES have an InspectionPacket Object
> and a Request Object but the relation is ManyToOne and I understand that
> Hibernate eagerly loads ManyToOne relationships. These two Objects'
> hashCode() methods are fine.
> 
> I really have no idea what is going on. Can someone give me a clue?
> 
> Thanks,
> Bob
> 

-- 
View this message in context: 
http://www.nabble.com/Lazy-Exception-again.-WTF--tp18357230s2369p18358012.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]

Reply via email to