When querying database information by parameter name using the HQL statement, "=:" cannot have spaces between parameters, otherwise it will error

Source: Internet
Author: User

Problem Description:

Today, when using HQL to query database information according to the name of the parameter, the error is as follows:

Org.hibernate.QueryException:Space is isn't allowed after parameter prefix ': ' [from Users user where user.address=: UserAddress] at Org.hibernate.engine.query.spi.ParameterParser.parse (Parameterparser.java:95) at Org.hibernate.engine.query.spi.ParamLocationRecognizer.parseLocations (Paramlocationrecognizer.java: 75) at Org.hibernate.engine.query.spi.HQLQueryPlan.buildParameterMetadata (Hqlqueryplan.java:289) at Org.hibernate.engine.query.spi.HQLQueryPlan.<init> (hqlqueryplan.java:124) at Org.hibernate.engine.query.spi.HQLQueryPlan.<init> (hqlqueryplan.java:80) at Org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan (Queryplancache.java:168) at Org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan (Abstractsessionimpl.java:219) at Org.hibernate.internal.AbstractSessionImpl.createQuery (Abstractsessionimpl.java:197) at Org.hibernate.internal.SessionImpl.createQuery (Sessionimpl.java:1736) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java:39) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java:25) at Java.lang.reflect.Method.invoke (Method.java:597) at Org.hibernate.context.internal.threadlocalsessioncontext$transactionprotectionwrapper.invoke ( Threadlocalsessioncontext.java:65W) at $Proxy 9.createQuery (Unknown Source) at Com.hibernate.HibernateSessionFactory.getQuery (hibernatesessionfact Ory.java:72) at Com.hibtest.entity.TestUsers.queryByNane (Testusers.java:217) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java:39) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java:25) at Java.lang.reflect.Method.invoke (Method.java:597) at org.junit.runners.model.frameworkmethod$1.runReflectiveCall (frameworkmethod.java:45) at Org.junit.internal.runners.model.ReflectiveCallable.run (Reflectivecallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively (Frameworkmethod.java:42) at Org.junit.internal.runners.statements.InvokeMethod.evaluate (Invokemethod.java:20) at Org.junit.runners.ParentRunner.runLeaf (Parentrunner.java:263) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (Blockjunit4classrunner.java:68) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (Blockjunit4classrunner.java:47) at org.junit.runners.parentrunner$3.run (parentrunner.java:231) at org.junit.runners.parentrunner$1.schedule (parentrunner.java:60) at Org.junit.runners.ParentRunner.runChildren (Parentrunner.java:229) at org.junit.runners.parentrunner.access$(parentrunner.java:50) at org.junit.runners.parentrunner$2.evaluate (parentrunner.java:222) at Org.junit.runners.ParentRunner.run (Parentrunner.java:300) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (Junit4testreference.java:50) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run (Testexecution.java:38) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (Remotetestrunner.java:467) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (Remotetestrunner.java:683) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (Remotetestrunner.java:390) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (Remotetestrunner.java:197)

The reason for this is that I have added extra space on both sides of the "=:" When I write the HQL statement, which causes the error to occur.

When querying database information by parameter name using the HQL statement, "=:" cannot have spaces between parameters, otherwise it will error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.