Reputation: 63
I work with hibernate-search-5.3.0.Beta2-dist , Eclipsse Indigo , Apache Tomcat v0.47
persitence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="Hibernate Tutozone" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>info.tutozone.food.Food</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tutozonedb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
</persistence-unit>
</persistence>
Food.java :
package info.tutozone.food;
import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;
/**
* Entity implementation class for Entity: Food
*
*/
@Entity
public class Food implements Serializable {
@Id
private int id;
private String name;
private float price;
private int quantity;
private static final long serialVersionUID = 1L;
public Food() {
super();
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return this.price;
}
public void setPrice(float price) {
this.price = price;
}
public int getQuantity() {
return this.quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
@Override
public String toString() {
return "Food [id=" + id + ", name=" + name + ", price=" + price
+ ", quantity=" + quantity + "]";
}
}
TestServlet.java :
package info.tutozone.food;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class TestServlet
*/
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
/*
* Tuto Hibernate avec Eclipse
* author : Zied
* www.tutozone.info
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
EntityManager manager=Persistence.createEntityManagerFactory("Hibernate Tutozone").createEntityManager();
manager.getTransaction().begin();
manager.getTransaction().commit();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
EntityManager manager = Persistence.createEntityManagerFactory(
"Hibernate Tutozone").createEntityManager();
manager.getTransaction().begin();
// add a new row in table
Food food = new Food();
food.setId(1);
food.setName("Cacke");
food.setQuantity(new Integer(20));
food.setPrice(new Float(2500));
manager.persist(food);
manager.getTransaction().commit();
manager.close();
}}
When I deploy this projet on tomcat I have this error on http://localhost:8080/HibernateTutoZone/TestServlet
type Exception report message Servlet execution threw an exception description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) root cause java.lang.NoClassDefFoundError: org/jboss/jandex/IndexView org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
I have this error on the console of Eclipsse Indigo:
SEVERE: Servlet.service() for servlet [info.tutozone.food.TestServlet] in context with path [/HibernateTutoZone] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: org.jboss.jandex.IndexView
I have no error if I do on my project run as->run configuation->Apache Tomcat->classpath->user Entries-> Add external jar -> jandex-1.1.0.final.jar
But even if I have no error , the main()of TestServlet.java is not working if I do that
Then I would like to understand what is the problem and how can I resolve it ?
Upvotes: 0
Views: 1507
Reputation: 20013
You can not use an external jar in this situation. Tomcat itself at runtime is responsible for deciding which jars it accepts as part of your application, which means get them into your web app's WEB-INF/lib
, one way or another.
And please stop using Indigo, it's almost 4 years old.
Upvotes: 0