jpa - org.apache.jasper.JasperException: java.lang.IllegalArgumentException: Object: emp.Customer[ id=100 ] is not a known entity type -
error coming whwne project start "org.apache.jasper.jasperexception: java.lang.illegalargumentexception: object: emp.customer[ id=100 ] not known entity type." how solve error plz tell me
1)newjsp.jsp
<%-- document : newjsp created on : oct 10, 2015, 1:10:21 pm author : niral --%>`enter code here` <%@page import="emp.*"%> <%@page import="javax.persistence.persistence"%> <%@page import="javax.persistence.entitymanager"%> <%@page import="javax.persistence.entitymanagerfactory"%> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>jsp page</title> </head> <body> <% entitymanagerfactory emf = persistence.createentitymanagerfactory("webapplicationjpapu"); entitymanager em = emf.createentitymanager(); //javax.transaction.usertransaction utx; customer c1 = new customer(); em.gettransaction().begin(); c1.setid(100l); c1.setbalance(10000); em.persist(c1); em.gettransaction().commit(); %> </body> </html> 2) /* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package emp; import java.io.serializable; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.*; import javax.persistence.id; /** * * @author niral */ @entity @table(name = "custmaster") public class customer implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.auto) @column(name = "custid") private long id; @column(name = "custbalance") private double balance; public double getbalance() { return balance; } public void setbalance(double balance) { this.balance = balance; } public long getid() { return id; } public void setid(long id) { this.id = id; } @override public int hashcode() { int hash = 0; hash += (id != null ? id.hashcode() : 0); return hash; } @override public string tostring() { return "emp.customer[ id=" + id + " ]"; } } 3)persistence.xml <?xml version="1.0" encoding="utf-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <persistence-unit name="webapplicationjpapu" transaction-type="jta"> <jta-data-source>jdbc/e4</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> </properties>`enter code here` </persistence-unit> </persistence>
your problem might similar post.
ideally, since inicated <exclude-unlisted-classes>false</exclude-unlisted-classes>
in persistence.xml file, should automatically detect entity classes in classpath. problem is, isn't doing reason.
if have small set of entity classes, or assuming have 1 entity manage (in case, customer entity), suggest explicitly list down entity classes in persistence.xml file. see example below:
<persistence-unit name="webapplicationjpapu" transaction-type="jta"> <class>emp.customer</class> ... </persistence-unit>
Comments
Post a Comment