0

I get a NullpointerException when I try to retrieve data from my database. I'm getting the exception at the for loop. I think it is an EventDispatchHandler problem, but I can't solve it. Can anybody help me please?

public class Dao {

private static final SessionFactory sessionFactory = NewHibernateUtil.getSessionFactory();

public List<OrderEntry> findAll(){
   try{
       sessionFactory.getCurrentSession().beginTransaction();
       return sessionFactory.getCurrentSession().createCriteria(OrderEntry.class).list();
   }catch(Exception e){
       return null;
   } 
}

JFrame

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {     

    loadData();
}                                        

private void loadData() {

   DefaultTableModel dtm = new DefaultTableModel();
   dtm.addColumn("Cause");
   dtm.addColumn("Lasttname");
   dtm.addColumn("Firstname");
   for(OrderEntry oe : this.dao.findAll()){
       dtm.addRow(new Object[] {oe.getCause(), oe.getLastname(), oe.getFirstname()});
}
   jTable1.setModel(dtm);
}

public class OrderEntry  implements java.io.Serializable {


 private Integer orderid;
 private String reference;
 private String type;
 private String cause;
 private String firstname;
 private String lastname;
 private String profession;
 private Set investigationMaterials = new HashSet(0);

public OrderEntry() {
}

public OrderEntry(String reference, String type, String cause, String firstname, String lastname, String profession, Set investigationMaterials) {
   this.reference = reference;
   this.type = type;
   this.cause = cause;
   this.firstname = firstname;
   this.lastname = lastname;
   this.profession = profession;
   this.investigationMaterials = investigationMaterials;
}

public Integer getOrderid() {
    return this.orderid;
}

public void setOrderid(Integer orderid) {
    this.orderid = orderid;
}
public String getReference() {
    return this.reference;
}

public void setReference(String reference) {
    this.reference = reference;
}
public String getType() {
    return this.type;
}

public void setType(String type) {
    this.type = type;
}
public String getCause() {
    return this.cause;
}

public void setCause(String cause) {
    this.cause = cause;
}
public String getFirstname() {
    return this.firstname;
}

public void setFirstname(String firstname) {
    this.firstname = firstname;
}
public String getLastname() {
    return this.lastname;
}

public void setLastname(String lastname) {
    this.lastname = lastname;
}
public String getProfession() {
    return this.profession;
}

public void setProfession(String profession) {
    this.profession = profession;
}
public Set getInvestigationMaterials() {
    return this.investigationMaterials;
}

public void setInvestigationMaterials(Set investigationMaterials) {
    this.investigationMaterials = investigationMaterials;
}

Exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at forensikmysql.UI.JInternalFrameShow.loadData(JInternalFrameShow.java:98)
    at forensikmysql.UI.JInternalFrameShow.jButton1ActionPerformed(JInternalFrameShow.java:89)
    at forensikmysql.UI.JInternalFrameShow.access$000(JInternalFrameShow.java:17)
    at forensikmysql.UI.JInternalFrameShow$1.actionPerformed(JInternalFrameShow.java:59)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6527)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6292)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4883)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4705)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4705)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1011) at forensikmysql.Util.Dao.findAll(Dao.java:22) at forensikmysql.UI.JInternalFrameShow.loadData(JInternalFrameShow.java:98) at forensikmysql.UI.JInternalFrameShow.jButton1ActionPerformed(JInternalFrameShow.java:89) at forensikmysql.UI.JInternalFrameShow.access$000(JInternalFrameShow.java:17) at forensikmysql.UI.JInternalFrameShow$1.actionPerformed(JInternalFrameShow.java:59) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6527) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6292) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4883) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4705) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2739) at java.awt.Component.dispatchEvent(Component.java:4705) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746) at java.awt.EventQueue.access$400(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:697) at java.awt.EventQueue$3.run(EventQueue.java:691) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:719) at java.awt.EventQueue$4.run(EventQueue.java:717) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:716) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Ben J.
  • 11
  • 5
  • That means `findAll()` returns null and so some exception is thrown in the try/catch in `findAll()`, inspect that exception to know what the problem is.. –  Aug 04 '16 at 14:42
  • Thanks for your answer. I added the Exception to my post. Maybe you can find something? – Ben J. Aug 04 '16 at 14:46
  • 1
    1) See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Aug 04 '16 at 14:48
  • That's not the interesting one: change `catch(Exception e){ return null; }` in `findAll()` to `catch(Exception e){ e.printStackTrace(); return null; }` and post this "e" –  Aug 04 '16 at 14:48
  • Thanks for the help. I added the stack trace. Can you please help me with it? – Ben J. Aug 05 '16 at 11:22
  • I solved it with your help. Thank you very much! – Ben J. Aug 05 '16 at 11:35

0 Answers0