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

后端 未结 3 2156
面向向阳花
面向向阳花 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:41

    Replace the load method with the get method..

    I found out after doing more research that the load method doesn't really load the object from the database. Instead it automatically returns a proxy object. Load assumes the object has already been "gotten with get" from the database and is in the cache.

    Just use get instead of load if you want to make sure you hit the database, and make sure you know the difference between these 2 methods.

    Source: this spring forum comment

    I've personally test this and it is right, the load method don't retrieve all the wanted data from the DB. Using get fixed my problem.

提交回复
热议问题