spring - org.hibernate.hql.internal.ast.QuerySyntaxException: is not mapped -


i using hibernate 4.x spring 4.x. unable retrieve entities database. saying entity not mapped.

stack trace:

java.lang.illegalargumentexception: org.hibernate.hql.internal.ast.querysyntaxexception: person not mapped [select p person p]     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1750)     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1677)     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1683)     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.createquery(abstractentitymanagerimpl.java:331)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ org.springframework.orm.jpa.sharedentitymanagercreator$sharedentitymanagerinvocationhandler.invoke(sharedentitymanagercreator.java:293)     @ com.sun.proxy.$proxy106.createquery(unknown source)     @ com.limeroad.services.hello.hibernate.persondao.selectall(persondao.java:36)     @ com.limeroad.services.hello.hibernate.persondao$$fastclassbyspringcglib$$6ea17c1.invoke(<generated>)     @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204)     @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:717)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157)     @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:99)     @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:281)     @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:96)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179)     @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:653)     @ com.limeroad.services.hello.hibernate.persondao$$enhancerbyspringcglib$$d54888ad.selectall(<generated>)     @ com.limeroad.services.hello.hibernate.personservice.fetchallpersons(personservice.java:31)     @ com.limeroad.services.hello.hibernate.personservice$$fastclassbyspringcglib$$f158ab64.invoke(<generated>)     @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204)     @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:649)     @ com.limeroad.services.hello.hibernate.personservice$$enhancerbyspringcglib$$da9402f0.fetchallpersons(<generated>)     @ com.limeroad.services.hello.hibernate.personcontroller.initiatepasswordrecovery(personcontroller.java:39)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ com.sun.jersey.spi.container.javamethodinvokerfactory$1.invoke(javamethodinvokerfactory.java:60)     @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemethoddispatchprovider$typeoutinvoker._dispatch(abstractresourcemethoddispatchprovider.java:185)     @ com.sun.jersey.server.impl.model.method.dispatch.resourcejavamethoddispatcher.dispatch(resourcejavamethoddispatcher.java:75)     @ com.sun.jersey.server.impl.uri.rules.httpmethodrule.accept(httpmethodrule.java:302)     @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(righthandpathrule.java:147)     @ com.sun.jersey.server.impl.uri.rules.resourceclassrule.accept(resourceclassrule.java:108)     @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(righthandpathrule.java:147)     @ com.sun.jersey.server.impl.uri.rules.rootresourceclassesrule.accept(rootresourceclassesrule.java:84)     @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequest(webapplicationimpl.java:1480)     @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequest(webapplicationimpl.java:1411)     @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:1360)     @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:1350)     @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:416)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:538)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:716)     @ javax.servlet.http.httpservlet.service(httpservlet.java:820)     @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:652)     @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:445)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137)     @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:556)     @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:227)     @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1044)     @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:372)     @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:189)     @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:978)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135)     @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:255)     @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:154)     @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116)     @ org.eclipse.jetty.server.server.handle(server.java:367)     @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:486)     @ org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection.java:937)     @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection.java:998)     @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:861)     @ org.eclipse.jetty.http.httpparser.parseavailable(httpparser.java:240)     @ org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection.java:82)     @ org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint.java:628)     @ org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.java:52)     @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:608)     @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:543)     @ java.lang.thread.run(thread.java:745) caused by: org.hibernate.hql.internal.ast.querysyntaxexception: person not mapped [select p person p]     @ org.hibernate.hql.internal.ast.querysyntaxexception.generatequeryexception(querysyntaxexception.java:96)     @ org.hibernate.queryexception.wrapwithquerystring(queryexception.java:120)     @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:234)     @ org.hibernate.hql.internal.ast.querytranslatorimpl.compile(querytranslatorimpl.java:158)     @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:126)     @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:88)     @ org.hibernate.engine.query.spi.queryplancache.gethqlqueryplan(queryplancache.java:190)     @ org.hibernate.internal.abstractsessionimpl.gethqlqueryplan(abstractsessionimpl.java:301)     @ org.hibernate.internal.abstractsessionimpl.createquery(abstractsessionimpl.java:236)     @ org.hibernate.internal.sessionimpl.createquery(sessionimpl.java:1800)     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.createquery(abstractentitymanagerimpl.java:328)     ... 68 more caused by: org.hibernate.hql.internal.ast.querysyntaxexception: person not mapped     @ org.hibernate.hql.internal.ast.util.sessionfactoryhelper.requireclasspersister(sessionfactoryhelper.java:189)     @ org.hibernate.hql.internal.ast.tree.fromelementfactory.addfromelement(fromelementfactory.java:109)     @ org.hibernate.hql.internal.ast.tree.fromclause.addfromelement(fromclause.java:95)     @ org.hibernate.hql.internal.ast.hqlsqlwalker.createfromelement(hqlsqlwalker.java:331)     @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromelement(hqlsqlbasewalker.java:3633)     @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromelementlist(hqlsqlbasewalker.java:3522)     @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromclause(hqlsqlbasewalker.java:706)     @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.query(hqlsqlbasewalker.java:562)     @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.selectstatement(hqlsqlbasewalker.java:299)     @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.statement(hqlsqlbasewalker.java:247)     @ org.hibernate.hql.internal.ast.querytranslatorimpl.analyze(querytranslatorimpl.java:278)     @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:206)     ... 76 more 

dbcontext.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:aop="http://www.springframework.org/schema/aop"     xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"     xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">      <context:annotation-config />      <bean id="entitymanagerfactory"         class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="packagestoscan" value="com.limeroad.services.*.dao.*" />         <property name="datasource" ref="datasource" />         <property name="jpavendoradapter">             <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter" />         </property>         <property name="jpaproperties">             <props>                 <prop key="hibernate.hbm2ddl.auto">validate</prop>                 <prop key="hibernate.dialect">org.hibernate.dialect.mysql5dialect</prop>             </props>         </property>     </bean>      <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager">         <property name="entitymanagerfactory" ref="entitymanagerfactory" />     </bean>      <tx:annotation-driven transaction-manager="transactionmanager" />      <bean id="datasource"         class="org.springframework.jdbc.datasource.drivermanagerdatasource">         <property name="driverclassname" value="com.mysql.jdbc.driver" />         <property name="url"             value="jdbc:mysql://localhost:3306/orderdb?autoreconnect=true" />         <property name="username" value="root" />         <property name="password" value="root" />     </bean>  </beans> 

persondao.java

package com.limeroad.services.hello.hibernate;  import java.util.list;  import javax.persistence.entitymanager; import javax.persistence.entitymanagerfactory; import javax.persistence.persistencecontext; import javax.persistence.query;  import org.springframework.stereotype.repository; import org.springframework.transaction.annotation.propagation; import org.springframework.transaction.annotation.transactional;  @repository("persondao") @transactional(propagation = propagation.required) public class persondao {    private static final string select_query = "select p person p";    @persistencecontext   private entitymanager entitymanager;    public entitymanager getentitymanager() {     return entitymanager;   }    public void setentitymanager(entitymanager entitymanager) {     this.entitymanager = entitymanager;   }    public void insert(person person) {     entitymanager.persist(person);   }    public list<person> selectall() {     query query = entitymanager.createquery(select_query);     list<person> persons = (list<person>) query.getresultlist();     return persons;   }  } 

person.java

package com.limeroad.services.hello.hibernate;  import javax.persistence.column; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.table; import javax.xml.bind.annotation.xmlrootelement;   @table(name = "person") @javax.persistence.entity @xmlrootelement(name = "person") public class person {   private integer id;   private string name;   private string email;    @id   @generatedvalue   @column(name = "id")   public integer getid() {     return id;   }    public void setid(integer id) {     this.id = id;   }    public string getname() {     return name;   }    public void setname(string name) {     this.name = name;   }    public string getemail() {     return email;   }    public void setemail(string email) {     this.email = email;   }    @override   public string tostring() {     return "person [id=" + id + ", name=" + name + ", email=" + email + "]";   }  } 

there lot of posts on stackoverflow in addressing same issue. unable find definite solution this.

please help

the value of <property name="packagestoscan" value="com.limeroad.services.*.dao.*" /> should packages entities in. in case should be

<property name="packagestoscan" value="com.limeroad.services.hello.hibernate" /> 

otherwise entity scanning mechanism won't find entity.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -