i use Hibernate 4 and Spring 3.
i have two entity.
Book entity
@Entity
@Table(name = \"book\")
public class Book implements Serializable {
Generally, when you call getter methods of entity classes(which returns relation object) out of transaction, then you get LazyInitializationException
s.
That's what might be happening in your case if you are converting entity class objects(retrieved from query) to json out of transaction.
I had same issue, I converted my entity object retrieved by hibernate to json in controller. As controller was out of transaction(Transaction at service layer), while converting to json, getter methods of entity class objects are called and I got LazyInitializationException
. Which obstructed object conversion to json, and response was not returned.
My solution, Try this :
@SuppressWarnings("unchecked")
@RequestMapping( method = RequestMethod.GET )
public @ResponseBody List getBook() {
List res = bookService.findAll();
for(Book book : res) {
book.getAuthor().setBooks(null);
}
return res;
}