org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]

J2EE 码拜 10年前 (2015-04-21) 1284次浏览 0个评论
 

执行SQL时异常提示:

org.hibernate.hql.ast.QuerySyntaxException: “””” is not mapped [sql string]

只要涉及数据库交互就会出现该异常。

框架用的jpa,实体上的注解也是有的


@Entity
@Table(name = "tableName")

“sql string” 中的表名与映射中的实体名完全一致(tableName)。

遇到该问题的童鞋解答一下,谢了

org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
3分
是不是对应数据库中的类型不对
org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
4分
这个确实应该是你映射的文件有一些不正确,不一定是表名,也很可能是某一字段的名字,或者类型之类的都会引起这个错误,你的错误信息贴出来的有点少,其实你仔细看应该会发现是哪个字段的,错误信息里应该有
org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
 异常信息


java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: SysUserInfo is not mapped [select o from SysUserInfo o where o.organId=""O00001"" and o.loginName=""admin""]
	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:617)
	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
	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.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:358)
	at $Proxy158.createQuery(Unknown Source)
	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.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:198)
	at $Proxy10.createQuery(Unknown Source)
	at com.daoyuan.common.dao.DaoSupport.getScrollData(DaoSupport.java:423)
	at com.daoyuan.base.service.impl.SysUserInfoServiceImpl.login(SysUserInfoServiceImpl.java:29)
	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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at $Proxy35.login(Unknown Source)
	at com.daoyuan.base.action.LoginAction.doLogin(LoginAction.java:44)
	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 com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:434)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:273)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:235)
	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:141)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:248)
	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:49)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:124)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:170)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:170)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	此处略去200字...

实体

@Entity
@Table(name = "Sys_UserInfo")
public class SysUserInfo implements java.io.Serializable {

	// Fields

	private String userId;
	private String loginName;
此处略去200字...
org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
10分
 <bean id=”sessionFactory” class=”org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean”>
       <property name=”dataSource” ref=”dataSource”></property>
       <property name=”hibernateProperties”>
         <props>        
               <prop key=”hibernate.dialect”>${hibernate.dialect}</prop>          
               <prop key=”hibernate.show_sql”>${hibernate.show_sql}</prop>
               <prop key=”hibernate.hbm2ddl.auto”>${hibernate.hbm2ddl.auto}</prop>
          </props>
       </property>
       <!– 扫描实体类 –>
       <property name=”packagesToScan” value=”com.torrent.entity”></property>

   </bean>

橘色的部分有问题

org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
1分
楼主问题解决没?我也越到了同样的问题!求解!
org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
1分
SysUserInfo is not mapped 
很明显了,SysUserInfo 这个实体没有被映射,检查一下注解,映射文件,或者packagesToScan的包名等一切有可能出问题的地方等等。
org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
1分
针对四楼给的答案去寻找该类是否被扫描到了.

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明org.hibernate.hql.ast.QuerySyntaxException: '' is not mapped [sql string]
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!