所以,在经过大量的搜索(徒劳)之后,我决定发布这个。所以,我正在使用Open JPA(2.2.0)开发这个Web应用程序。执行该应用程序会抛出以下错误:
控制台打印输出:
<openjpa-2.3.0-r422266:1540826 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
Entities.User".
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:115)
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:312)
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:236)
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:212)
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:155)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
Servlet.Registration.doPost(Registration.java:78)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
设定:
<?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="persistenceUnit">
<class>Entities.User</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/alda" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="openjpa.jdbc.DBDictionary" value="mysql" />
<!-- Cette propriété active la log des requêtes SQL réalisées par OpenJPA -->
<property name="openjpa.Log" value="SQL=Trace" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
</persistence>
注册类别:
public class Registration extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String firstName = request.getParameter("firstName");
String email = request.getParameter("email");
String password = request.getParameter("password");
String confirmation = request.getParameter("confirmation");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
System.out.println("Ajout d'un utilisateur:"+name+","+firstName+","+email+","+password+","+confirmation);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
User u = new User();
u.setName(name);
u.setFirstName(firstName);
u.setPassword(password);
u.setEmail(email);
u.setAddress(address);
u.setPhone(phone);
em.persist(u);
em.getTransaction().commit();
this.getServletContext().getRequestDispatcher("/Home.jsp").forward(request, response);
}
}
3条答案
按热度按时间5hcedyr01#
您是否配置了构建时增强?OpenJPA需要修改类文件以使用它们,因此您应该允许它在某个时候这样做。这个doc page给出了如何做的一个很好的概述。例如,它可以通过maven来完成。另一种方法是运行时增强。
qyzbxkaa2#
我没有配置的增强和在你和我的日志,我看到这个“实体.用户”.这是什么意思,我说?回答:例如,双重检查你的代码和我的代码是否存在一些错误。在我的情况下,它是双重@Id:列ID和用户名!这是一个魔术。
iqxoj9l93#
只需在persistence.xml文件中添加一个提供程序,如下所示: