1

Consider entity

public class User {
...
@OneToMany(cascade = CascadeType.ALL)
List<SocialCredential> credentialsList = new ArrayList<SocialCredential>();
}

with DAO Implementation method

@Transactional
@Override
public User getUser(long id){
  Session s = sessionFactory.getCurrentSession();
  User asu = (User) s.get(User.class, id);
  return asu;
}

and Controller

@Controller
public class DummyController {
  @Autowired
  UserDAO userDAO;

  public void anyMethodAccessedByGetORPost(){
    User u= userDAO.getUser(1L);
  }
}

My question is why a simple query for entity User automatically fires query to initialize entity list of SocialCredential ? Ultimately it leads to LazyInitializationException.Is there anything wrong with Google App Engine.I have tried the same on Apache Tomcat which fires one query without eagerly initializing entity list SocialCredential with success.Afterwards ,I have used both local Jetty server and also tried after deploying it to GAE Server,but no success.I am not interested to EAGERLY load list SocialCredential.

1 Answer 1

2

Use OpenSessionInViewFilter filter to open the session on filter level. Once after that you'll not get this kind of error.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for introducing OpenSessionInViewFilter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.