Cześć
Zaczynam poznawanie frameworka Hibernate i mam mały problem.
Na stronie mam formularz ,który przesyła POST'em dane do servletu.
Servlet odczytuje dane - na tym etapie jest wszystko ok.
Dane te chciałbym zapisać do bazy z użyciem hibernate.
Jednak wyskakuje mi taki oto exception
Nazwa servletu : Test
Servlet.service() for servlet [com.tomek.ReadData] in context with path [/Test] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
Plik hibernate.cfg.xml - w katalogu src
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/extdb</property>
<property name="connection.username">mojUser</property>
<property name="connection.password">mojehaselko</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files will go here.... -->
<mapping class="com.tomek.UserBean" /> // moj obiekt do zapisu
</session-factory>
</hibernate-configuration>
I kod servletu Test
WebServlet("/ReadData")
public class ReadData extends HttpServlet {
private static final long serialVersionUID = 1L;
public ReadData() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userFirstName = request.getParameter("name");
String userLastName = request.getParameter("lastname");
UserBean user = new UserBean();
user.setUserName(userFirstName);
user.setUserLastName(userLastName);
System.out.println(user.toString());
// Mamy dane
// Wkladamy dane do bazy danych
// Odpalam Hibernate
@SuppressWarnings("deprecation")
SessionFactory sesionFactory = new Configuration().configure().buildSessionFactory();
Session session = sesionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();
}
}
Dodam ,że gdy tworze sobie testowa klasie javy w pakiecie com.tomek z metoda main to zapis do bazy danych dziala
Mam dziwne przeczucie ,że podczas wdrożenia aplikacji do kontenera servletow ( uzywam Tomcat'a ) nie sa wrzucane libsy z hibernate.