Salve ragazzi vi porto sotto i dati del mio progetto con in conclusione l'eccezione che tomcat mi lancia.
[hibernate.cfg.xml]
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/farmacia
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">danilo</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="model.Turni.hbm.xml"/>
</session-factory>
</hibernate-configuration>
[Turni.hbm.xml]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.Turni" table="turni">
<id name="id" column="id" type="long">
<generator class="assigned"/>
</id>
<property name="descrizione" column="descrizione" type="String"/>
<property name="data" column="data" type="String"/>
</class>
</hibernate-mapping>
[TurniDAO]
package dao;
import model.Turni;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.hql.ast.util.SessionFactoryHelper;
public class TurniDAO {
private Session session;
public void InsertTurniDB(Turni t){
try{
//permette di leggere il file di configurazione di hibernate e di preparare hibernate per l'uso
//apre la sessione tra l'applicazione e il db
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("Inserting Record");
Transaction tx = session.beginTransaction();
Turni turni =t;
session.save(turni);
tx.commit();
System.out.println("Done");
}catch(Exception e){ e.printStackTrace();}
finally{
session.flush();
session.close();
}
}
}
[eccezione al passaggio dei dati nel form dopo il submit]
GRAVE: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at dao.TurniDAO.InsertTurniDB(TurniDAO.java:30)
at actions.InsertTurniAction.execute(InsertTurniActio n.java:26)
at org.apache.struts.chain.commands.servlet.ExecuteAc tion.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAc tion.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase .execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.exe cute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor .process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)