exception - org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User] where User is my bean class -
i using hibernate gwt want retrieve data table, have created dto class , simple java class in have initialized dto object.
in server side storing result in array list , using each loop storing query result user type , calling private method using dto object.
my code fine getting below exception...and while retrieving firing "from user" query user simple bean class
this hibernate.cfg.xml file
<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/rs</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="connection.release_mode">auto</property> <!-- jdbc connection pool (use built-in) --> <property name="connection.pool_size">10</property> <!-- mysql dialect --> <property name="dialect">org.hibernate.dialect.mysqldialect</property> <!-- disable second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.nocacheprovider</property> <!-- echo executed sql stdout --> <property name="show_sql">true</property> <!-- drop , re-create database schema on startup --> <property name="hbm2ddl.auto">update</property> <property name="hibernate.hbm2ddl.import_files"></property> <!-- names annotated entity class --> <mapping class="com.valto.querybrowser.client.model.user"/> <mapping class="com.valto.querybrowser.client.model.userdto"/> </session-factory> </hibernate-configuration>
this dto class userdto.java
@entity(name="usertable") @table(name="usertable") public class userdto implements serializable{ private static final long serialversionuid = -5753020447289277291l; @id @generatedvalue(strategy=generationtype.identity) @column(name="userid") private int id; @column(name="user_name") private string user_name; public userdto() { } public userdto(int id) { this.id=id; } public userdto(int id,string user_name) { this.id=id; this.user_name=user_name; } public int getid() { return id; } public void setid(int id) { this.id = id; } public string getuser_name() { return user_name; } public void setuser_name(string user_name) { this.user_name = user_name; } }
this simple bean class user.java
public class user { public int id; public string user_name; public user(userdto udto) { id=udto.getid(); user_name=udto.getuser_name(); } }
and server side code..
@override public list<userdto> getusers(string getinput) throws illegalargumentexception { session session = sessionfacorycode.getsessionfactory().opensession(); system.out.println(getinput+"\n"); try { session.begintransaction(); list<user> user = new arraylist<user>(session.createquery(getinput).list()); list<userdto> userdto = new arraylist<userdto>(user != null ? user.size() : 0); if (user != null) { (user user1 : user) { userdto.add(createuserdto(user1)); } } session.gettransaction().commit(); return userdto; } catch (exception e) { getinput=null; e.printstacktrace(); return null; } { session.close(); } } private userdto createuserdto(user user1) { return new userdto(user1.id,user1.user_name); }
this sessionfactorycode.java
public class sessionfacorycode { private static final sessionfactory sessionfactory; static { try { configuration cfg = new configuration().configure(); serviceregistry serviceregistry = new serviceregistrybuilder() . applysettings(cfg.getproperties()).buildserviceregistry(); sessionfactory =cfg.buildsessionfactory(serviceregistry); } catch (throwable th) { system.err.println("enitial sessionfactory creation failed" + th); throw new exceptionininitializererror(th); } } public static sessionfactory getsessionfactory() { return sessionfactory; } }
this error after adding @entity in user.java...
caused by: org.hibernate.annotationexception: no identifier specified entity: com.valto.querybrowser.client.model.user @ org.hibernate.cfg.inheritancestate.determinedefaultaccesstype(inheritancestate.java:277) @ org.hibernate.cfg.inheritancestate.getelementstoprocess(inheritancestate.java:224) @ org.hibernate.cfg.annotationbinder.bindclass(annotationbinder.java:665) @ org.hibernate.cfg.configuration$metadatasourcequeue.processannotatedclassesqueue(configuration.java:3533) @ org.hibernate.cfg.configuration$metadatasourcequeue.processmetadata(configuration.java:3487) @ org.hibernate.cfg.configuration.secondpasscompile(configuration.java:1376) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1777) @ com.valto.querybrowser.client.model.sessionfacorycode.<clinit>(sessionfacorycode.java:16) ... 36 more [error] 500 - post /querybrowser/greet (127.0.0.1) 57 bytes request headers host: 127.0.0.1:8888 connection: keep-alive content-length: 145 x-gwt-module-base: http://127.0.0.1:8888/querybrowser/ x-gwt-permutation: hostedmode origin: http://127.0.0.1:8888 user-agent: mozilla/5.0 (windows nt 6.1) applewebkit/537.36 (khtml, gecko) chrome/37.0.2062.120 safari/537.36 content-type: text/x-gwt-rpc; charset=utf-8 accept: */* referer: http://127.0.0.1:8888/querybrowser.html?gwt.codesvr=127.0.0.1:9997 accept-encoding: gzip,deflate accept-language: en-gb,en-us;q=0.8,en;q=0.6 response headers content-type: text/plain [warn] exception while dispatching incoming rpc call com.google.gwt.user.server.rpc.unexpectedexception: service method 'public abstract java.util.list com.valto.querybrowser.client.greetingservice.gettablenames() throws java.lang.illegalargumentexception' threw unexpected exception: java.lang.noclassdeffounderror: not initialize class com.valto.querybrowser.client.model.sessionfacorycode @ com.google.gwt.user.server.rpc.rpc.encoderesponseforfailure(rpc.java:389) @ com.google.gwt.user.server.rpc.rpc.invokeandencoderesponse(rpc.java:579) @ com.google.gwt.user.server.rpc.remoteserviceservlet.processcall(remoteserviceservlet.java:265) @ com.google.gwt.user.server.rpc.remoteserviceservlet.processpost(remoteserviceservlet.java:305) @ com.google.gwt.user.server.rpc.abstractremoteserviceservlet.dopost(abstractremoteserviceservlet.java:62) @ javax.servlet.http.httpservlet.service(httpservlet.java:755) @ javax.servlet.http.httpservlet.service(httpservlet.java:848) @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:686) @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:501) @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137) @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:557) @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:231) @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1086) @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:428) @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:193) @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:1020) @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135) @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116) @ org.eclipse.jetty.server.handler.requestloghandler.handle(requestloghandler.java:68) @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116) @ org.eclipse.jetty.server.server.handle(server.java:370) @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:489) @ org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection.java:960) @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection.java:1021) @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:865) @ 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:668) @ 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(unknown source) caused by: java.lang.noclassdeffounderror: not initialize class com.valto.querybrowser.client.model.sessionfacorycode @ com.valto.querybrowser.server.greetingserviceimpl.gettablenames(greetingserviceimpl.java:33) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ com.google.gwt.user.server.rpc.rpc.invokeandencoderesponse(rpc.java:561) ... 30 more
this piece of code causing problem.
list<user> user = new arraylist<user>(session.createquery(getinput).list());
you trying fetch list database, , don not have table mapped against user
.
@entity
required added user.java
.
Comments
Post a Comment