Hibernate hangs or throws lazy initialization no session or session was closed

后端 未结 3 2153
面向向阳花
面向向阳花 2021-02-12 14:54

I\'m enhancing an old Spring/Hibernate application and im stuck. I have a method that reads a file 3000+ lines long, each line has a record which has to be compared with somethi

3条回答
  •  无人共我
    2021-02-12 15:40

    I've had the same problem before, and fixed it by using different hibernate methods. I use

    getHibernateTemplate().loadAll(class)
    

    for getting all of something, and

    getHibernateTemplate().get(class, id) 
    

    to find a single thing. Both of those I use with no problems. I found that .find() gives me that session was closed error.

    I haven't really looked into why this is though.

    The only other option I can think of aside from using another method is to open and close sessions yourself, but I presume you prefer not to do that.

提交回复
热议问题