- 实体:**
@Entity
@Table(name="user_account")
public class UserAccount implements Serializable{
private static final long serialVersionUID = -2606506548742732094L;
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer id;
- 持久性. xml**
<persistence-unit name="Maze" transaction-type="RESOURCE_LOCAL">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mazedb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
- 错误**
WARNING: #{accountController.performLogin}: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [com.maze.model.UserAccount] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>com.maze.model.UserAccount</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
javax.faces.FacesException: #{accountController.performLogin}: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [com.maze.model.UserAccount] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>com.maze.model.UserAccount</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
- 行为**每次我重新启动Web容器时,在几分钟内一切正常,然后抛出此错误。我错过了什么?
- 编辑:**
现在我也在应用程序范围内使用了一个实体,同样的错误也发生在Country实体上。User和Country都被定义为persistance.xml中的类。此外,exclude-unlisted-classes被设置为false。
SEVERE: Critical error during deployment:
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39 )
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:256)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:255)
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2000)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1651)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:294)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:462)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [com.maze.model.Country] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>com.maze.model.Country</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:174)
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:194)
at org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.from(AbstractQueryImpl.java:97)
at com.maze.service.CountryService.readList(CountryService.java:74)
at com.maze.util.MazeConstants.<clinit>(MazeConstants.java:26)
国家实体:
@Entity
@Table(name = "country")
public class Country implements Serializable{
private static final long serialVersionUID = 4086034429815316972L;
@Id
private Integer id;
private String name;
private String continent;
private Integer population;
private Float surface;
@OneToMany(mappedBy = "country")
private List<User> userList;
现在,该实体用于应用程序范围,并且该实体抛出此错误,Glassfish无法完全启动。
- 第二次编辑:**根据当前行为,Web容器似乎在第一次热部署之前启动并正常工作。
6条答案
按热度按时间qojgxg4l1#
问题是你的应用程序的热部署。旧的持久性单元在服务器上停留,因为你从来没有关闭旧的工厂,所以在热部署之后工厂仍然有旧的类,所以你得到了类转换错误。
您需要清除旧的持久性单元。关闭EntityManagerFactory应该可以完成此操作,例如在Servlet销毁回调中。
如果你使用一个管理持久单元,那么所有的东西都应该被自动清理,问题在于你如何管理你的持久单元。
我认为在EclipseLink上也有一个bug,你可能想为这个bug投票。
b5lpy0ml2#
我曾经遇到过类似的问题。异常有时会被抛出,有时不会。在痛苦的调试时间之后,我发现它是由类路径上的另一个jar中包含的第二个persistence.xml文件(包含同名的持久性单元)引起的。
wlp8pajw3#
您可以手动将类添加到persistence.xml吗?理想情况下,您不需要这样做,但它至少会给予您一个开始。
<persistence-unit><class>com.maze.model.UserAccount</class>...
irlmq6kh4#
我也遇到过类似的问题,我重构了代码,更改了类名,但是资源注入仍然试图注入旧的类名。重命名持久化单元解决了这个问题(随后恢复名称又重新引入了这个问题)。
更新:经过进一步的搜索,我发现了一个持久性类的jar文件。我创建它是为了解决以前的构建问题。使问题更加复杂的是,我还重命名了我的项目。虽然我已经从工作区中删除了持久性JAR,但它仍然挂在eclipse的. xxx文件夹中的旧项目名称下。我删除了它和所有对旧项目的引用,我的构建得到了修复。从而去除无[实体类型]消息。
jv4diomz5#
意外复制持久性文件也可能导致此情况
有时Netbeans可以在webModule中自动生成持久性文件,如果您在库模块中有持久性文件,它将被自动生成的新的空持久性文件覆盖。因此,也可能发生此错误
x8goxv8g6#
经过一些尝试和错误,以下工作为我.
假设module1包含类c1和c2,module2包含类c3并依赖于module1。我们的应用程序包含类c5并依赖于module2。
确保module1和module2不包含persistence.xml persistence.xml文件在主应用程序中应包含以下条目
以上条目是必需的,即使您具有以下条目
它解决了以下所有问题:
1.列表项
1.实体有时被识别,有时不被识别。
1.应用程序在正常模式下运行良好,但在eclipse调试模式下失败并出现错误。
1.应用程序使用命令mvn spring-boot:run运行良好,但使用java-jar target\app.jar失败