java - Hibernate query, QueryException exception -
i have query:
final query query2 = session.createquery("from calldetailhistoriesentity unique_id = :id or unique_id in (select linked_id calldetailhistoriesentity unique_id = :id)");
but have exception. why?
[nioeventloopgroup-5-5] error com.corundumstudio.socketio.listener.defaultexceptionlistener - org.hibernate.queryexception: no data type node: org.hibernate.hql.internal.ast.tree.identnode \-[ident] identnode: 'linked_id' {originaltext=linked_id} [from hibernate.entity.calldetailhistoriesentity unique_id = :id or unique_id in (select linked_id hibernate.entity.calldetailhistoriesentity unique_id = :id)] java.lang.illegalargumentexception: org.hibernate.queryexception: no data type node: org.hibernate.hql.internal.ast.tree.identnode \-[ident] identnode: 'linked_id' {originaltext=linked_id} [from hibernate.entity.calldetailhistoriesentity unique_id = :id or unique_id in (select linked_id hibernate.entity.calldetailhistoriesentity unique_id = :id)] @ org.hibernate.internal.exceptionconverterimpl.convert(exceptionconverterimpl.java:131) @ org.hibernate.internal.exceptionconverterimpl.convert(exceptionconverterimpl.java:155) @ org.hibernate.internal.exceptionconverterimpl.convert(exceptionconverterimpl.java:162) @ org.hibernate.internal.abstractsharedsessioncontract.createquery(abstractsharedsessioncontract.java:662) @ org.hibernate.internal.abstractsharedsessioncontract.createquery(abstractsharedsessioncontract.java:102) @ socketio.listeners.callhistorylistener.ondata(callhistorylistener.java:27) @ socketio.listeners.callhistorylistener.ondata(callhistorylistener.java:22) @ com.corundumstudio.socketio.namespace.namespace.onevent(namespace.java:134) @ com.corundumstudio.socketio.handler.packetlistener.onpacket(packetlistener.java:103) @ com.corundumstudio.socketio.handler.inpackethandler.channelread0(inpackethandler.java:92) @ com.corundumstudio.socketio.handler.inpackethandler.channelread0(inpackethandler.java:36) @ io.netty.channel.simplechannelinboundhandler.channelread(simplechannelinboundhandler.java:105) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ io.netty.handler.codec.bytetomessagedecoder.channelread(bytetomessagedecoder.java:187) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ io.netty.channel.defaultchannelpipeline.firechannelread(defaultchannelpipeline.java:846) @ com.corundumstudio.socketio.transport.websockettransport.channelread(websockettransport.java:94) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ io.netty.handler.codec.messagetomessagedecoder.channelread(messagetomessagedecoder.java:103) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ com.corundumstudio.socketio.transport.pollingtransport.channelread(pollingtransport.java:109) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ com.corundumstudio.socketio.handler.authorizehandler.channelread(authorizehandler.java:132) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ io.netty.channel.simplechannelinboundhandler.channelread(simplechannelinboundhandler.java:108) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ io.netty.handler.codec.bytetomessagedecoder.channelread(bytetomessagedecoder.java:182) @ io.netty.channel.abstractchannelhandlercontext.invokechannelread(abstractchannelhandlercontext.java:308) @ io.netty.channel.abstractchannelhandlercontext.firechannelread(abstractchannelhandlercontext.java:294) @ io.netty.channel.defaultchannelpipeline.firechannelread(defaultchannelpipeline.java:846) @ io.netty.channel.nio.abstractniobytechannel$niobyteunsafe.read(abstractniobytechannel.java:130) @ io.netty.channel.nio.nioeventloop.processselectedkey(nioeventloop.java:511) @ io.netty.channel.nio.nioeventloop.processselectedkeysoptimized(nioeventloop.java:468) @ io.netty.channel.nio.nioeventloop.processselectedkeys(nioeventloop.java:382) @ io.netty.channel.nio.nioeventloop.run(nioeventloop.java:354) @ io.netty.util.concurrent.singlethreadeventexecutor$2.run(singlethreadeventexecutor.java:116) @ io.netty.util.concurrent.defaultthreadfactory$defaultrunnabledecorator.run(defaultthreadfactory.java:137) @ java.lang.thread.run(thread.java:745) caused by: org.hibernate.queryexception: no data type node: org.hibernate.hql.internal.ast.tree.identnode \-[ident] identnode: 'linked_id' {originaltext=linked_id} [from hibernate.entity.calldetailhistoriesentity unique_id = :id or unique_id in (select linked_id hibernate.entity.calldetailhistoriesentity unique_id = :id)] @ org.hibernate.queryexception.generatequeryexception(queryexception.java:120) @ org.hibernate.queryexception.wrapwithquerystring(queryexception.java:103) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:218) @ org.hibernate.hql.internal.ast.querytranslatorimpl.compile(querytranslatorimpl.java:142) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:115) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:77) @ org.hibernate.engine.query.spi.queryplancache.gethqlqueryplan(queryplancache.java:153) @ org.hibernate.internal.abstractsharedsessioncontract.getqueryplan(abstractsharedsessioncontract.java:545) @ org.hibernate.internal.abstractsharedsessioncontract.createquery(abstractsharedsessioncontract.java:654) ... 41 more caused by: org.hibernate.queryexception: no data type node: org.hibernate.hql.internal.ast.tree.identnode \-[ident] identnode: 'linked_id' {originaltext=linked_id} @ org.hibernate.hql.internal.ast.tree.selectclause.initializeexplicitselectclause(selectclause.java:160) @ org.hibernate.hql.internal.ast.hqlsqlwalker.useselectclause(hqlsqlwalker.java:991) @ org.hibernate.hql.internal.ast.hqlsqlwalker.processquery(hqlsqlwalker.java:759) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.query(hqlsqlbasewalker.java:675) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.collectionfunctionorsubselect(hqlsqlbasewalker.java:4918) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.inrhs(hqlsqlbasewalker.java:4819) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.comparisonexpr(hqlsqlbasewalker.java:4486) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.logicalexpr(hqlsqlbasewalker.java:2134) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.logicalexpr(hqlsqlbasewalker.java:2087) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.whereclause(hqlsqlbasewalker.java:813) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.query(hqlsqlbasewalker.java:607) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.selectstatement(hqlsqlbasewalker.java:311) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.statement(hqlsqlbasewalker.java:259) @ org.hibernate.hql.internal.ast.querytranslatorimpl.analyze(querytranslatorimpl.java:262) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:190) ... 47 more
///////////////////////////////////// hibernate entity: ///////////////////////////////////// ///////////////////////////////////// /////////////////////////////////////
@entity @dynamicupdate @dynamicinsert @table(name = "call_detail_histories", schema = "mydb", catalog = "") public class calldetailhistoriesentity { private int id; private string unique_id; private string source_caller_id; private string dest_caller_id; private timestamp start_time; private timestamp eventtime; private string current_status; private string linkedid; @id @column(name = "id") public int getid() { return id; } public void setid(int id) { this.id = id; } @basic @column(name = "unique_id") public string getunique_id() { return unique_id; } public void setunique_id(string unique_id) { this.unique_id = unique_id; } @basic @column(name = "source_caller_id") public string getsource_caller_id() { return source_caller_id; } public void setsource_caller_id(string source_caller_id) { this.source_caller_id = source_caller_id; } @basic @column(name = "dest_caller_id") public string getdest_caller_id() { return dest_caller_id; } public void setdest_caller_id(string dest_caller_id) { this.dest_caller_id = dest_caller_id; } @basic @column(name = "start_time") public timestamp getstart_time() { return start_time; } public void setstart_time(timestamp start_time) { this.start_time = start_time; } @basic @column(name = "event_time", insertable = false) public timestamp geteventtime() { return eventtime; } public void seteventtime(timestamp eventtime) { this.eventtime = eventtime; } @basic @column(name = "status") public string getcurrent_status() { return current_status; } public void setcurrent_status(string current_status) { this.current_status = current_status; } @basic @column(name = "linked_id") public string getlinkedid() { return linkedid; } public void setlinkedid(string linkedid) { this.linkedid = linkedid; } @override public boolean equals(object o) { if (this == o) return true; if (o == null || getclass() != o.getclass()) return false; calldetailhistoriesentity = (calldetailhistoriesentity) o; if (id != that.id) return false; if (unique_id != null ? !unique_id.equals(that.unique_id) : that.unique_id != null) return false; if (source_caller_id != null ? !source_caller_id.equals(that.source_caller_id) : that.source_caller_id != null) return false; if (dest_caller_id != null ? !dest_caller_id.equals(that.dest_caller_id) : that.dest_caller_id != null) return false; if (start_time != null ? !start_time.equals(that.start_time) : that.start_time != null) return false; if (eventtime != null ? !eventtime.equals(that.eventtime) : that.eventtime != null) return false; if (current_status != null ? !current_status.equals(that.current_status) : that.current_status != null) return false; return true; } @override public int hashcode() { int result = id; result = 31 * result + (unique_id != null ? unique_id.hashcode() : 0); result = 31 * result + (source_caller_id != null ? source_caller_id.hashcode() : 0); result = 31 * result + (dest_caller_id != null ? dest_caller_id.hashcode() : 0); result = 31 * result + (start_time != null ? start_time.hashcode() : 0); result = 31 * result + (eventtime != null ? eventtime.hashcode() : 0); result = 31 * result + (current_status != null ? current_status.hashcode() : 0); return result; } }
your entity doesn't have property named linked_id
. has 1 named linkedid
, though. that's should use in jpql query.
i advise stick java naming conventions: variables , methods never have underscore in java, , use camelcase. renamed unique_id
uniqueid
, source_caller_id
sourcecallerid
, etc. of course, getters , query should changed accordingly.
the next step realize whole point of jpa/hibernate have graph of entities, interconnected using associations. should probaby not have linkedid
attribute of type string in entity, rather manytoone or onetoone association entity. that's allwos navigating graph of entities in code, , using joins in queries.
Comments
Post a Comment