Nie chce mi odpalić apka. Wszystkie jest testowe i brzydko napisane chodzi tylko aby sie odpaliło.
persistence.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="hib">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Osoba</class>
<properties>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.password" value="********"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/testowa"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
Serwlet który ma to odpalić
@WebServlet("/index")
public class index extends HttpServlet {
private static final long serialVersionUID = 1L;
private static EntityManagerFactory emf;
EntityManager em;
public index() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
emf = Persistence.createEntityManagerFactory("hib");
em = emf.createEntityManager();
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
Wiem wiem w servlecie nie powinno byc danych ale to tylko test.
Encja
@Entity
@Table(name="osoba")
public class Osoba{
@Id
@GeneratedValue
int id;
String imie;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getImie() {
return imie;
}
public void setImie(String imie) {
this.imie = imie;
}
}
widok projektu
http://zapodaj.net/63bd3d4eac16b.png.html