hi when i run my application using hibernate to insert in database sql 5.0 i get this exception:
Exception in thread "main" java.lang.NullPointerException at org.domain.projet.config.Facade.createConnexion(Facade.java:227) at org.domain.projet.config.Test.main(Test.java:49) 5 mai 2011 10:41:27 net.sf.hibernate.impl.SessionImpl finalize
this i开发者_Go百科s the method:
public Connexion createConnexion( int id_utilisateur) throws HibernateException
{
Connexion con =new Connexion();
con.setDateDeb(new Date());
con.setDateFin(new Date());
con.setIdCnx(id_utilisateur);
Session session = sessFactory.openSession();
net.sf.hibernate.Transaction tx=null;
try {
tx = session.beginTransaction();
Utilisateur user=(Utilisateur) session.load(Utilisateur.class,id_utilisateur);
con.setUtil(user);
//((List<Connexion>)user.getConnexions()).add((Connexion) con);
user.getConnexions().add(con);
session.saveOrUpdate(user);
session.saveOrUpdate(con);
//session.flush();
tx.commit();
}
catch (HibernateException he) {
if (tx!=null) tx.rollback();
throw he;
}
finally {
session.close();
}
return con;
}
The stack trace tells you exactly where the error lies : at line 227, in the class Facade
, and in the method createConnexion
. At this line, you probably call a method on a null reference. Without seeing the code, it's impossible to be more precise.
BTW : what's the relation between the title and the body of your question?
精彩评论