Java 持久性无法识别实体类

Java 持久性无法识别实体类,java,jpa,eclipselink,Java,Jpa,Eclipselink,我正在开发一个关于我国一些彩票的java程序,它有一个包含彩票和其他号码的数据库。实体类没有问题,但当我运行该问题时,我的持久化单元无法识别一个实体类。我是java的初学者,提前谢谢 以下是数字实体类: @实体 @Tablename=数字 @XmlRootElement @命名查询{ @NamedQueryname=Numbers.findAll,query=从数字n中选择n ,@NamedQueryname=Numbers.findById,query=从数字n中选择n,其中n.id=:id

我正在开发一个关于我国一些彩票的java程序,它有一个包含彩票和其他号码的数据库。实体类没有问题,但当我运行该问题时,我的持久化单元无法识别一个实体类。我是java的初学者,提前谢谢

以下是数字实体类:

@实体 @Tablename=数字 @XmlRootElement @命名查询{ @NamedQueryname=Numbers.findAll,query=从数字n中选择n ,@NamedQueryname=Numbers.findById,query=从数字n中选择n,其中n.id=:id ,@NamedQueryname=Numbers.findByNum,query=从数字n中选择n,其中n.num=:num和n.lotto=:lotto ,@NamedQueryname=Numbers.findbyasociated,query=从数字n中选择n,其中n.num=:num和n.associated=:associated和n.lotto=:lotto ,@NamedQueryname=Numbers.findByLotto,query=从数字n中选择n,其中n.lotto=:lotto} 公共类编号实现可序列化{ 私有静态最终长serialVersionUID=1L; @身份证 @GeneratedValuestrategy=GenerationType.IDENTITY @基本选项=假 @Columnname=ID 私有整数id; @基本选项=假 @Columnname=NUM 私有整数; @基本选项=假 @Columnname=关联 私人关联; @基本选项=假 @Columnname=乐透 私人串乐透; 以及我用来在数据库中插入数字的代码:

公共静态布尔值InsertalEntityManager em,数字和{ 布尔成功=假; Alert Alert=Check.createAlertCheck.CONFIRMATION,Añadir números asociados,Deseas Añadir estos números?; 可选结果=alert.showAndWait; 如果result.get==ButtonType.OK{ em.getTransaction.begin; 埃姆·帕斯坦; 如果em.isJoinedToTransaction{ em.getTransaction.commit; System.out.PrintLnNumber已成功添加!; alert=Check.createAlertCheck.INFORMATION,OK,Números añadidos!; alert.show和wait; 成功=真实; } em.clear; } 回归成功; } persistence.xml文件:

org.eclipse.persistence.jpa.PersistenceProvider 乐透,乐透,戈多 乐透 乐透,乐透,欧洲头彩 乐透 乐透 乐透 乐透 乐透,乐透,欧米隆 乐透,重复 乐透,号码 持久化单元识别我所有的实体类,但不识别这个,我不知道如何解决这个问题

Caused by: java.lang.IllegalArgumentException: Object: lotter.Numbers[ id=null ] is not a known entity type.
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4228)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496)
    at lotter.Numbers.insertAlert(Numbers.java:165)
    at lotter.Numbers.insertAssociated(Numbers.java:150)
    at lotter.Lotter.start(Lotter.java:41)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application lotter.Lotter
JPA日志记录:

[EL Finer]: metadata: 2019-10-17 16:14:45.632--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Searching for default mapping file in file:/Users/~/NetBeansProjects/Lotter/build/classes/ (There is no English translation for this message.)
[EL Finer]: metadata: 2019-10-17 16:14:45.643--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Searching for default mapping file in file:/Users/~/NetBeansProjects/Lotter/build/classes/ (There is no English translation for this message.)
[EL Config]: metadata: 2019-10-17 16:14:45.803--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Bonoloto] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.825--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Euromillones] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.827--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.Repetition] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.832--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Gordo] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.833--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Seis49] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.834--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Primitiva] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.835--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Siete39] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.835--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Superonce] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.836--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Eurojackpot] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.837--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Bonoloto] is being defaulted to: Bonoloto.
[EL Config]: metadata: 2019-10-17 16:14:45.868--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Euromillones] is being defaulted to: Euromillones.
[EL Config]: metadata: 2019-10-17 16:14:45.869--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.Repetition] is being defaulted to: Repetition.
[EL Config]: metadata: 2019-10-17 16:14:45.87--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Gordo] is being defaulted to: Gordo.
[EL Config]: metadata: 2019-10-17 16:14:45.871--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Seis49] is being defaulted to: Seis49.
[EL Config]: metadata: 2019-10-17 16:14:45.873--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Primitiva] is being defaulted to: Primitiva.
[EL Config]: metadata: 2019-10-17 16:14:45.874--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Siete39] is being defaulted to: Siete39.
[EL Config]: metadata: 2019-10-17 16:14:45.875--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Superonce] is being defaulted to: Superonce.
[EL Config]: metadata: 2019-10-17 16:14:45.878--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Eurojackpot] is being defaulted to: Eurojackpot.
[EL Finest]: jpa: 2019-10-17 16:14:46.059--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--End predeploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 0
[EL Finer]: weaver: 2019-10-17 16:14:46.059--Thread(Thread[JavaFX Application Thread,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: jpa: 2019-10-17 16:14:46.059--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Begin predeploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 0
[EL Finest]: jpa: 2019-10-17 16:14:46.059--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--End predeploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 1
[EL Finest]: jpa: 2019-10-17 16:14:46.065--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Begin deploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 1
[EL Finer]: 2019-10-17 16:14:46.088--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
[EL Finest]: properties: 2019-10-17 16:14:46.092--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--property=eclipselink.logging.logger; value=org.eclipse.persistence.logging.DefaultSessionLog

Persist只接受实体,而不接受实体的列表

因此,您必须迭代数组并分别保存每个Numbers对象

 for (Numbers n : ans) {
     em.persist(ans);
 }

此错误的常见原因:

旧的persistence.xml文件位于类路径上,而该类路径没有 有你的彩票。号码输入。 用于获取EntityManager的类加载器不同 加载了您要传递给的“an”应答实例的 坚持打电话。 第一个问题要常见得多,在部署持久化单元时检查日志以查看加载了哪些类和映射,可以更容易地发现。它的变体只是部署了错误的jar,在类路径上首先有一个旧的jar等等


EclipseLink使用类在哈希映射中查找元数据,因此如果使用不同的类加载器,它将找不到任何元数据。这是一个不太常见的问题,取决于您如何加载EntityManagerFactory和容器类加载器结构。您可能会遇到不止一个JPA实体的问题,但它不会uld也取决于它们来自何处。

我也有同样的问题,但这里的答案都没有解决


我的解决方案是将我的EclipseLink版本从2.5.1更新到2.7.7,如本文所述。

我更改了代码,这不是我以前尝试过的问题……感谢您的回答。我已经测试过,PU没有映射数字类,它忽略了它。我删除了persistence.xml并创建了新的,与数据库相同ase,但问题仍然存在。我能做什么?它不会忽略所有实体中的一个实体。打开日志记录-当需要处理numbers类或记录persistence.xml和其他实体类的位置时,它会显示什么?您是否验证了cla上只有一个lotter.numbers类文件ss路径和JPA注释?我在我的帖子中添加了日志记录程序显示,我没有发现问题,没有重复的存档或其他同名jar。是否有其他persistence.xml文件,可能在/Users/~/NetBeansProjects/Lotter/build/classes/目录或meta inf目录中
ubdirectory?不,没有。我已经做了三次同样的项目,问题总是在那里。。。