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 7988817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:34:05+00:00 2026-06-04T12:34:05+00:00

I am using JPA, Hibernate and Spring MVC. In the controller class all the

  • 0

I am using JPA, Hibernate and Spring MVC. In the controller class all the methods works greatly. When I test them in the web browser the public String getModuleFormation(long id) method, that returns an object, and it gives me the following error:

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

as a root cause, but yesterday I tried it, and it worked without problem in the localhost:45045/GestionModules/detail/xx URL.

What could cause this problem?

My detail.jsp:

<c:if test="${!empty detailModule}">

${detailModule.idModule}
${detailModule.libModule}
</c:if>

POJO Class + JPA :

@Entity
@Table(name="ModuleFormation")
public class ModuleFormation {

private long idModule;
private String libModule;

public ModuleFormation() {
    // TODO Auto-generated constructor stub
}

public ModuleFormation(String libModule) {
    this.libModule = libModule;
}

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "seqModule")
@SequenceGenerator(name="seqModule", sequenceName = "seqModuleFormation")
@Column(name="idModule")
public long getIdModule() {
    return this.idModule;
}

public void setIdModule(long idModule) {
    this.idModule = idModule;
}

@Column(name="libModule", nullable=false, length = 100)
public String getLibModule() {
    return this.libModule;
}

public void setLibModule(String libModule) {
    this.libModule = libModule;
}

}

DAO Class :

@Repository
public class ModuleFormationDAOImpl implements ModuleFormationDAO {

@Autowired
private SessionFactory sessionFactory;


public void ajouterModuleFormation(ModuleFormation module) {
    sessionFactory.getCurrentSession().save(module);
}

public void supprimerModuleFormation(long idModule) {
    ModuleFormation module = (ModuleFormation) sessionFactory.getCurrentSession().load(ModuleFormation.class, idModule);
    if(module != null)
        sessionFactory.getCurrentSession().delete(module);
}

public List<ModuleFormation> listModuleFormation() {
    
    return sessionFactory.getCurrentSession().createQuery("from ModuleFormation")
            .list();
    
}

public ModuleFormation getModuleFormation(long idModule) {
     return (ModuleFormation) sessionFactory.getCurrentSession().load(ModuleFormation.class, idModule);
}

public void majModuleFormation(ModuleFormation module) {
    sessionFactory.getCurrentSession().merge(module);
}

}

Service Class :

@Service
public class ModuleFormationServiceImpl implements ModuleFormationService {

@Autowired
private ModuleFormationDAO moduleDao;

@Transactional
public void ajouterModuleFormation(ModuleFormation module) {
    moduleDao.ajouterModuleFormation(module);
}

@Transactional
public void supprimerModuleFormation(long idModule) {
    moduleDao.supprimerModuleFormation(idModule);
}

@Transactional
public List<ModuleFormation> listModuleFormation() {
    return moduleDao.listModuleFormation();
}

@Transactional
public ModuleFormation getModuleFormation(long idModule) {
    return moduleDao.getModuleFormation(idModule);
}

@Transactional
public void majModuleFormation(ModuleFormation module) {
    moduleDao.majModuleFormation(module);
}
}

Controller Class :

@Controller
public class ModuleFormationController {

@Autowired
private ModuleFormationService moduleService;

@RequestMapping("/module")
public String listModulesFormations(Map<String, Object> map) {
    
    map.put("module", new ModuleFormation());
    map.put("moduleList", moduleService.listModuleFormation());
    
    return "module";
}

@RequestMapping(value = "/ajouter", method = RequestMethod.POST )
public String ajouterModuleFormation(@ModelAttribute("module")
ModuleFormation module,BindingResult result) {
    
    moduleService.ajouterModuleFormation(module);
    
    return "redirect:/module";
}


@RequestMapping(value = "/supprimer/{idModule}")
public String supprimerModuleFormation(@PathVariable("idModule")
long idModule) {
    moduleService.supprimerModuleFormation(idModule);
    
    return "redirect:/module";
}


@RequestMapping(value= "/detail/{idModule}")
public String getModuleFormation(@PathVariable("idModule")
long idModule,Map<String, Object> map) {
    map.put("detailModule", moduleService.getModuleFormation(idModule));
    return "/detail";
}

    
@RequestMapping(value= "/detail/modifier", method = RequestMethod.POST )
public String majModuleFormation(@ModelAttribute("detailModule")
ModuleFormation module, BindingResult result) {
    moduleService.majModuleFormation(module);
    return "detail/{idModule}";
}

}
  • 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-06-04T12:34:07+00:00Added an answer on June 4, 2026 at 12:34 pm

    The Javadoc on the Hibernate Session#load(Class, Serializable) method says:

    Return the persistent instance of the given entity class with the given identifier,
    assuming that the instance exists. This method might return a proxied instance that
    is initialized on-demand, when a non-identifier method is accessed.

    When you access a property on the object in your JSP the session which loaded the object has been closed.

    Use Session#get(Class, Serializable) to ensure that you don’t load a proxy.

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

Sidebar

Related Questions

I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate
My web application is using Java, Hibernate's JPA implementation (EntityManager) and Spring. What are
I´m using JPA Hibernate and Spring MVC. I haved implemented repository pattern. I get
I am using JPA (with hibernate as the provider) in spring for a web-app.
I am building a new web app and I am using Spring, JPA/Hibernate, and
I'm developing an example web-application, using JPA 2.0 entities, Hibernate 3.6.2 and Spring 3.
I am using Spring 3, JPA + Hibernate for a CMS application. In that
I'm using Spring with Hibernate as a JPA provider and are trying to get
I am using Hibernate 3.6, JPA 2.0, and Spring 3.0.6. I have fields in
I'm building a webapp using JQuery, Stripes, Spring and JPA (Hibernate). I have 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.