Tuesday, 15 April 2014

java - Unable to retrieve EntityManagerFactory for unitName null -


I try to use JSP by creating simple eclipse dynamic web projects.

I have created an original JSP and a form that creates a parametric request for HTTservelet.

I am using mapping via annotation.

This is my jasp:

   & Lt; Input type = "hidden" name = "firstname" value = '& lt; Jsp: getProperty property = "firstname" name = "new customer" /> / & Gt; & Lt; Input type = "hidden" name = "last name" value = '& lt; Jsp: getProperty property = "lastname" name = "newCustomer" /> / & Gt; & Lt; / Form & gt;   

... This is the main part of my Bean:

  @intexty table (name = "customer") public class customerbill serializable {@ id @column (name = "CUSTOMER_ID") private long id; @column (name = "FIRST_NAME") private string firstname; @column (name = "LAST_NAME") private string last name; Public clientben () {this.firstname = ""; This.lastname = ""; } // Theater & amp; SATERS   

And now - finally - this is my very easy servlet: @WebServlet (name = "persistenceDemo", urlPatterns = {"/ persistencedemo "}) Public Class Persistence Demo HTTPSVervlet {Private Static Finals Long Serial Weerission UID = 1 L; @ Precision University Private Unit Enterprise Unit MANAGERFactory; @Resource Personal UserTransaction UserTransaction; @ Override protected Zero doGet (HTTPPrilateral request), HttpServletResponse resp) ServletException throws, IOException {EntityManager em = entityManagerFactory.createEntityManager (); Customerbene C1 = new customerbusiness (); Customerbene C2 = new customerbusiness (); C1.setFirstname ("my"); C1.setLastname ("self"); C1.setId (3l); C2.setId (4L); C2.setFirstname (req.getParameter ("firstName")); C2.setLastname (req.getParameter ("lastName")); Try {UserTransaction.begin (); Em.persist (c1); Em.persist (c2); UserTransaction.commit (); } Hold (exception e) {e.printStackTrace (); } Resp.getWriter () Print ("Update Database!"); }}

[Update] My persistence.xml

  & lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Persistence xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schema location = "http://java.sun.com/xml/ns/pressistence http: // Java Sun. Com / xml / ns / persistence / persistence_2_0.xsd "version =" 2.0 "xmlns =" ​​http://java.sun.com/xml/ns/spearness "& gt; & Lt; Firm-entity name = "hello-world" transaction type = "RESOURCE_LOCAL" & gt; & Lt; Classes & gt; Com.jpa.PersistenceDemo & lt; / Square & gt; & Lt; Properties & gt; & Lt; Property Name = "javax.persistence.jdbc.url" value = "jdbc: mysql: // localhost: 3306 / customer db" /> & Lt; Property Name = "javax.persistence.jdbc.driver" value = "com.mysql.jdbc.Driver" /> & Lt; Property Name = "javax.persistence.jdbc.user" value = "customeruser" /> & Lt; Property Name = "javax.persistence.jdbc.password" value = "customerpass" /> & Lt; / Properties & gt; & Lt; / Persistence unit & gt; & Lt; / Persistence>   

Problem : I have linked and created tables to my SQL connector, but all the time when I entityManagerFactory.createEntityManager () This crashes with an error message:

  Unable to retrieve the entity name EntityManagerFactory   

OK, on ​​one hand the fact is that I should probably use any other structure from different model (bean) view (JSP):

What's the problem here?

  1. Your Perseverance Where is the Xml file located?

  2. Maybe there is a wrong structure in this project? Is EJB in its separate part? Try to pack some parts of the project.

    In whatever program you write java and see that "

No comments:

Post a Comment