Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save an object into JSF Session
    primarykey
    data
    text
    <p>I try to save the object into sessionmap but it is giving me an exception</p> <pre><code>public class testclass { public static void main(String[] args) throws IOException { UserInfo ui = new UserInfo(); UserLogin ul= new UserLogin(); ui.setAdds("India"); ui.setEId("someone@yahoo.com"); ui.setFName("someone"); ui.setLName("someone2"); ui.setStatus("single"); ul.setPswd("somename"); ul.setUserId("121"); ul.setUserinfo(ui); AnnotationConfiguration config = new AnnotationConfiguration(); config.configure("hibernate.cfg.xml"); //new SchemaExport(config).create(true, true); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); System.out.println("Session configured"); session.beginTransaction(); session.save(ul); System.out.println("object saved"); Query q = session.createQuery("from UserLogin where UserId='121'"); UserLogin user = (UserLogin)q.uniqueResult(); if(user!=null) { ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); Map&lt;String, Object&gt; sessionMap = externalContext.getSessionMap(); sessionMap.put("User",user); UserLogin hd = (UserLogin)sessionMap.get("User"); System.out.println("the user id is "+hd.getUserId()); } session.getTransaction().commit(); </code></pre> <p>}</p> <p>Exception:</p> <blockquote> <p>Exception in thread "main" java.lang.NullPointerException at BeanMngr.testclass.main(testclass.java:58) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)</p> </blockquote> <p>How is this problem caused and how can I solve it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload