JPA 异常 : java.lang.NoSuchFieldError: NONE

本文介绍了一种在使用Java持久化API (JPA)时遇到的java.lang.NoSuchFieldError:NONE异常及其解决方案。该异常通常发生在尝试加载或查询实体类时,并通过检查和清理重复的jar包来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java.lang.NoSuchFieldError: NONE I am getting this run time exception when I am running my hello world program using JPA . The code is as mentioned below -- // Second unit of work EntityManager newEm = emf.createEntityManager(); EntityTransaction newTx = newEm.getTransaction(); newTx.begin(); //Exception is thrown at this point List messages = newEm.createQuery("select m from Message m order by m.text asc").getResultList(); for (Object m : messages) { Message loadedMsg = (Message) m; System.out.println(loadedMsg.getText()); } newTx.commit(); newEm.close(); }catch(Exception e){e.printStackTrace();} // Shutting down the application emf.close(); } The jars which I am using are mentioned below -- 1)ejb3-persistence-1.0.2.GA 2)hibernate3 3)hibernate-entitymanager-3.5.1-Final 4)hibernate-jpa-2.0-api-1.0.0.Final 5)hibernate-validator-4.0.2.GA Database which I am using is hsqldb I will be very much obliged for the solution of the same , I feel that it is related to versions of the jars but not sure which one to use.

以上内容摘自网络:

List<User> ls = em.createNativeQuery("select * from users").getResultList();

在执行到如上代码的时候抛出一个异常:


原因是 jar包重复了, 原来我既导入了 JavaEE 5 又单独导入了 java-persistence-api

删除 JavaEE5 问题解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值