spring - org.hibernate.hql.internal.ast.QuerySyntaxException: Circle is not mapped [from Circle] -
i building sample spring hibernate application.spring part working fine.in hibernate have mapped bean class , table.still error saying bean class not mapped.please find attached code reference.need fixing this.
circle.java package re.test; import javax.persistence.entity; import javax.persistence.id; import org.hibernate.annotations.*; import javax.persistence.table; @entity @table(name = "employeemaster1") public class circle { @id private int id; private string name; public int getid() { return id; } public void setid(int id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } } hibernatedaoimpl.java package re.test; import org.hibernate.query; import org.hibernate.sessionfactory; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.repository; @repository public class hibernatedaoimpl { @autowired private sessionfactory sessionfactory; public void setsessionfactory(sessionfactory sessionfactory) { this.sessionfactory = sessionfactory; } public sessionfactory getsessionfactory() { return sessionfactory; } public int gettablecount() { system.out.println("test"); string varsql = "from circle"; query query = getsessionfactory().opensession().createquery(varsql); return ((long) query.uniqueresult()).intvalue(); } } jdbcdemo.java package re.test; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class jdbcdemo { public static void main(string[] args) { applicationcontext ctx = new classpathxmlapplicationcontext("spring.xml"); hibernatedaoimpl dao = ctx.getbean("hibernatedaoimpl",hibernatedaoimpl.class); int cnt = dao.gettablecount(); } } spring.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:context="http://www.springframework.org/schema/context" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package = "re.test" /> <bean id="circle" class="re.test.circle" autowire="byname"> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource" autowire="byname"> <property name="driverclassname" value="com.microsoft.sqlserver.jdbc.sqlserverdriver"/> <property name="url" value="jdbc:sqlserver://localhost:1433;databasename=javadb"/> <property name="username" value="sa"/> <property name="password" value="dbadmin@234"/> </bean> <bean id="hibernatedaoimpl" class="re.test.hibernatedaoimpl"/> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="datasource"/> <property name="hibernateproperties"> <props> <prop key="dialect">org.hibernate.dialect.sqlserverdialect</prop> </props> </property> </bean> </beans> following stack trace aug 08, 2016 4:53:10 pm org.springframework.context.support.classpathxmlapplicationcontext preparerefresh info: refreshing org.springframework.context.support.classpathxmlapplicationcontext@1077fc9: startup date [mon aug 08 16:53:10 ist 2016]; root of context hierarchy aug 08, 2016 4:53:10 pm org.springframework.beans.factory.xml.xmlbeandefinitionreader loadbeandefinitions info: loading xml bean definitions class path resource [spring.xml] aug 08, 2016 4:53:11 pm org.springframework.jdbc.datasource.drivermanagerdatasource setdriverclassname info: loaded jdbc driver: com.microsoft.sqlserver.jdbc.sqlserverdriver aug 08, 2016 4:53:12 pm org.hibernate.annotations.common.version <clinit> info: hcann000001: hibernate commons annotations {4.0.3.final} aug 08, 2016 4:53:12 pm org.hibernate.version logversion info: hhh000412: hibernate core {4.3.11.final} aug 08, 2016 4:53:12 pm org.hibernate.cfg.environment <clinit> info: hhh000206: hibernate.properties not found aug 08, 2016 4:53:12 pm org.hibernate.cfg.environment buildbytecodeprovider info: hhh000021: bytecode provider name : javassist aug 08, 2016 4:53:12 pm org.hibernate.dialect.dialect <init> info: hhh000400: using dialect: org.hibernate.dialect.sqlserver2008dialect aug 08, 2016 4:53:12 pm org.hibernate.engine.transaction.internal.transactionfactoryinitiator initiateservice info: hhh000399: using default transaction strategy (direct jdbc transactions) aug 08, 2016 4:53:12 pm org.hibernate.hql.internal.ast.astquerytranslatorfactory <init> info: hhh000397: using astquerytranslatorfactory test **exception in thread "main" org.hibernate.hql.internal.ast.querysyntaxexception: circle not mapped [from circle] @ 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:131) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:93) @ org.hibernate.engine.query.spi.queryplancache.gethqlqueryplan(queryplancache.java:167) @ org.hibernate.internal.abstractsessionimpl.gethqlqueryplan(abstractsessionimpl.java:301) @ org.hibernate.internal.abstractsessionimpl.createquery(abstractsessionimpl.java:236) @ org.hibernate.internal.sessionimpl.createquery(sessionimpl.java:1836) @ re.test.hibernatedaoimpl.gettablecount(hibernatedaoimpl.java:26) @ re.test.jdbcdemo.main(jdbcdemo.java:14) caused by: org.hibernate.hql.internal.ast.querysyntaxexception: circle 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:338) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromelement(hqlsqlbasewalker.java:3678) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromelementlist(hqlsqlbasewalker.java:3567) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromclause(hqlsqlbasewalker.java:708) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.query(hqlsqlbasewalker.java:564) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.selectstatement(hqlsqlbasewalker.java:301) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.statement(hqlsqlbasewalker.java:249) @ org.hibernate.hql.internal.ast.querytranslatorimpl.analyze(querytranslatorimpl.java:278) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:206) ... 9 more**
spring error bean not registered in spring.xml. using xml based configuration, please check spring classes.it should similar to:
<beans:bean id="hibernate4annotatedsessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <beans:property name="datasource" ref="datasource" /> <beans:property name="annotatedclasses"> <beans:list> <beans:value>com.mypackage.model.person</beans:value> </beans:list> </beans:property> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect"> org. hibernate.dialect. mysqldialect </beans:prop> <beans:prop key="hibernate.show_sql">true</beans:prop> </beans:props> </beans:property> </beans:bean>
Comments
Post a Comment