Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6902615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:49:14+00:00 2026-05-27T07:49:14+00:00

I have a Database where user and address data is stored in separate tables.

  • 0

I have a Database where user and address data is stored in separate tables. When a user logs in to my page I want to show him a form with which he can change his user/account data. However, I end up getting an Exception: org.hibernate.LazyInitializationException: could not initialize proxy - no Session. The address attributes can’t be loaded. The user loads just fine and that’s what I don’t understand. My AddressDAOImpl looks like this:

@Autowired
private SessionFactory sessionFactory;
public void addAddress(Address address) 
{
        sessionFactory.getCurrentSession().save(address);
}
public void updateAddress(Address address) 
{
    sessionFactory.getCurrentSession().update(address);     
}
public List<Address> listAddress() 
{
    return sessionFactory.getCurrentSession().createQuery("from address").list();
}
public void deleteAddress(int id) 
{
    Address addr = (Address) sessionFactory.getCurrentSession().load(Address.class, id);
    if(addr != null)
    {
        sessionFactory.getCurrentSession().delete(addr);
    }
}
public Address getAddress(int id) 
{
        return (Address) sessionFactory.getCurrentSession().load(Address.class, id);    
}

My Controller does this:

@RequestMapping("/library/home")
public ModelAndView showHome()
{
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    User user = userService.getUser(username);
    Address address = addressService.getAddress(user.getId());
    ModelMap mmap = new ModelMap();
    mmap.addAttribute("user", user);
    mmap.addAttribute("addresse", address);
    return new ModelAndView("/library/home", mmap);
}

Why doesn’t this work? And why does it work for the user data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:49:15+00:00Added an answer on May 27, 2026 at 7:49 am

    I’m assuming that your AddressService created the transaction used to load the Address proxy (it’s a proxy because you used load() instead of get()). The session associated with this transaction is closed when you return the Address from the AddressService.

    By the time your view resolver tries to access the attributes of the Address proxy, there is no session available through which a database query can be run to fetch the attributes. Hence the exception.

    Either use get() instead of load(), or access the attributes while you’re still in the scope of the transaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which collects user info including name, location, url, email address
I have database application, I want to allow the user to restore the deleted
I have a database with three tables: user_table country_table city_table I want to write
I have a php page which shows an entire time schedule for a user
I am trying to setup a simple database in which I have a user
In my Rails application, I have a variety of database tables that contain user
I have a database with user 'dbo' that has a login name domain\xzy. How
I have a database in single user mode and I am trying to drop
i have a large user Database (13k+), and for some reason i need to
I have a postgres database with a user table (userid, firstname, lastname) and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.