Hibernate异常之命名查询节点未找到

异常信息:

 1 java.lang.IllegalArgumentException: No query defined for that name [salaryEmps]
 2     at org.hibernate.internal.AbstractSharedSessionContract.getNamedQuery(AbstractSharedSessionContract.java:578)
 3     at org.hibernate.internal.AbstractSharedSessionContract.getNamedQuery(AbstractSharedSessionContract.java:103)
 4     at pw.fengya.test.TestHibernate.testNamedQuery(TestHibernate.java:59)
 5     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 6     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 7     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 8     at java.lang.reflect.Method.invoke(Method.java:483)
 9     at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:389)
10     at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
11     at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:167)
12     at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$201/5021240.execute(Unknown Source)
13     at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
14     at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:163)
15     at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:110)
16     at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:57)
17     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$3(HierarchicalTestExecutor.java:83)
18     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$$Lambda$133/1144648478.execute(Unknown Source)
19     at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
20     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)
21     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$null$2(HierarchicalTestExecutor.java:92)
22     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$$Lambda$136/1681595665.accept(Unknown Source)
23     at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
24     at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
25     at java.util.Iterator.forEachRemaining(Iterator.java:116)
26     at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
27     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
28     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
29     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
30     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
31     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
32     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
33     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$3(HierarchicalTestExecutor.java:92)
34     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$$Lambda$133/1144648478.execute(Unknown Source)
35     at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
36     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)
37     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$null$2(HierarchicalTestExecutor.java:92)
38     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$$Lambda$136/1681595665.accept(Unknown Source)
39     at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
40     at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
41     at java.util.Iterator.forEachRemaining(Iterator.java:116)
42     at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
43     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
44     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
45     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
46     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
47     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
48     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
49     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$3(HierarchicalTestExecutor.java:92)
50     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$$Lambda$133/1144648478.execute(Unknown Source)
51     at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
52     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)
53     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:51)
54     at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
55     at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
56     at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
57     at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
58     at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86)
59     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
60     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
61     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
62     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
63     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
64     Suppressed: org.hibernate.TransactionException: Transaction was marked for rollback only; cannot commit
65         at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:228)
66         at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
67         at pw.fengya.test.TestHibernate.destory(TestHibernate.java:48)
68         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
69         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
70         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
71         at java.lang.reflect.Method.invoke(Method.java:483)
72         at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:389)
73         at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
74         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeMethodInExtensionContext(ClassTestDescriptor.java:289)
75         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$synthesizeAfterEachMethodAdapter$12(ClassTestDescriptor.java:281)
76         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor$$Lambda$156/644166178.invokeAfterEachMethod(Unknown Source)
77         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$null$9(TestMethodTestDescriptor.java:208)
78         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$205/1991386317.execute(Unknown Source)
79         at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
80         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:226)
81         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$203/1393112209.accept(Unknown Source)
82         at java.util.ArrayList.forEach(ArrayList.java:1234)
83         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAllAfterMethodsOrCallbacks(TestMethodTestDescriptor.java:224)
84         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAfterEachMethods(TestMethodTestDescriptor.java:207)
85         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114)
86         ... 48 more

学习Hibernate的命名查询时突然抛出异常,最后检查是由于自己太粗心了,query节点应该放在class节点外,与之同级

 1 <?xml version="1.0"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 4
 5 <hibernate-mapping package="pw.fengya.bean">
 6
 7     <class name="Employee" table="t_EMPLOYEE">
 8
 9         <id name="id" type="java.lang.Integer">
10             <column name="ID" />
11             <generator class="native" />
12         </id>
13
14         <property name="name" type="java.lang.String">
15             <column name="NAME" />
16         </property>
17
18         <property name="salary" type="float">
19             <column name="SALARY" />
20         </property>
21
22         <property name="email" type="java.lang.String">
23             <column name="EMAIL" />
24         </property>
25
26         <many-to-one name="dept" class="Deptartment" fetch="select">
27             <column name="DEPT_ID" />
28         </many-to-one>
29
30         <query name="salaryEmps"><![CDATA[FROM Employee e WHERE e.salary > :minSal AND e.salary < :maxSal]]></query>
31     </class>
32
33 </hibernate-mapping>

将query标签拿出来,与class同级即可

原文地址:https://www.cnblogs.com/lxc-2017/p/8553565.html

时间: 2024-10-11 08:13:30

Hibernate异常之命名查询节点未找到的相关文章

Hibernate-ORM:14.Hibernate中的命名查询

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述命名查询,所谓命名查询是什么呢? Hibernate中允许我们在xml,实体类,甚至注解的方式来编写查询语句,本篇博客将讲述xml中的方式 一,准备好准备工作,我由于上篇博客把大量的准备都做好,所以,本篇从简 二,预览hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hi

Windows服务安装异常:System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security

原文地址:http://blog.csdn.net/joyhen/article/details/42262305 2种方法处理: 一.右键单击“以管理员身份运行”Visual Studio Command Prompt即可 二.以管理员身份运行vs,然后打开项目,再执行InstallService程序安装服务. 附:具体构建windows 服务,可以看看这篇文章:http://www.cnblogs.com/LoveJenny/archive/2013/03/05/2943691.html

12.hibernate命名查询

1.创建如下javaweb项目结构 2.在项目的src下创建hibernate.cfg.xml主配置文件 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourc

Hibernate命名查询

什么是命名查询? Hibernate允许在映射文件中定义字符串形式的查询语句,这种查询方式成为命名查询 使用命名查询有什么好处? 由于使用Hibernate的HQL常常需要在Java代码中写字符串查询语句,HQL混杂在代码之间,破坏代码可读性,通过使用命名查询,可以使业务逻辑和查询语句分离,使您专注于查询,而避免了 SQL 或者 HQL 代码分散于整个应用程序中的情况. 可以应用命名查询做复杂查询的处理 命名查询如何实现? 介绍下面几种方式: 方法一:在配置文件中<class/>标记的下面,声

Hibernate(十三)命名查询-批量处理和调用存储过程

一.命名查询 HQL语句混杂在代码之间将破坏代码的可读性 Hibernate允许在映射配置文件中定义字符串形式的查询语句,这种查询方式称为命名查询 二.建立数据表和持久化类 建立数据表 create table login ( username varchar2(32) primary key, password varchar2(32) not null , age number(3) ); insert into login select '张三','123456',21 from dual

[原创]java WEB学习笔记90:Hibernate学习之路-- -HQL检索方式,分页查询,命名查询语句,投影查询,报表查询

本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱好者,互联网技术发烧友 微博:伊直都在0221 QQ:951226918 -----------------------------------------------------------------------------------------------------------------

在与 SQL Serve2008r 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) j解决方案

在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) 今早开机发现,打开SQL Server 2008 的 SQL Server Management Studio,输入sa的密码发现,无法登陆数据库?提示以下错误: “在与 SQL Server 建立连接时出现与网络相关

Hibernate学习笔记--------4.查询

一.Get/Load Get方法是立即检索,而load是延迟检索,他们都是根据主键进行查询.在<class>标签中,若把lazy属性改为false,load方法就会立即检索,class中的lazy属性仅对load方法有效.在使用load时,当数据库没有找到数据时,会有ObjectNotFoundException,异常. 1 public void LazyTest() { 2 //lazy 改为false或者true,查看打印sql的时机 3 Tb_User u = session.load

Hibernate 异常总结

异常一 异常一 异常描述: Sax解析异常:cvc-复杂的类型,发现了以元素maping开头的无效内容,应该是以 '{"http://www.hibernate.org/xsd/orm/cfg":property, "http://www.hibernate.org/xsd/orm/cfg":mapping, "http://www.hibernate.org/xsd/orm/cfg":class-cache, "http://www.