简体   繁体   中英

Hibernate query, QueryException exception

i have a Query:

final Query query2 = session.createQuery("FROM CallDetailHistoriesEntity WHERE unique_id = :id OR unique_id IN (SELECT linked_id FROM CallDetailHistoriesEntity WHERE unique_id = :id)");

But i have exception. Why?

[nioEventLoopGroup-5-5] ERROR com.corundumstudio.socketio.listener.DefaultExceptionListener - org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode 
 \-[IDENT] IdentNode: 'linked_id' {originalText=linked_id}
 [FROM hibernate.entity.CallDetailHistoriesEntity WHERE unique_id = :id OR unique_id IN (SELECT linked_id FROM hibernate.entity.CallDetailHistoriesEntity WHERE unique_id = :id)]
java.lang.IllegalArgumentException: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode 
 \-[IDENT] IdentNode: 'linked_id' {originalText=linked_id}
 [FROM hibernate.entity.CallDetailHistoriesEntity WHERE unique_id = :id OR unique_id IN (SELECT linked_id FROM hibernate.entity.CallDetailHistoriesEntity WHERE unique_id = :id)]
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:131)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662)
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:102)
    at socketio.listeners.CallHistoryListener.onData(CallHistoryListener.java:27)
    at socketio.listeners.CallHistoryListener.onData(CallHistoryListener.java:22)
    at com.corundumstudio.socketio.namespace.Namespace.onEvent(Namespace.java:134)
    at com.corundumstudio.socketio.handler.PacketListener.onPacket(PacketListener.java:103)
    at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:92)
    at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:36)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:187)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at com.corundumstudio.socketio.transport.WebSocketTransport.channelRead(WebSocketTransport.java:94)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at com.corundumstudio.socketio.transport.PollingTransport.channelRead(PollingTransport.java:109)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at com.corundumstudio.socketio.handler.AuthorizeHandler.channelRead(AuthorizeHandler.java:132)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:108)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:182)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode 
 \-[IDENT] IdentNode: 'linked_id' {originalText=linked_id}
 [FROM hibernate.entity.CallDetailHistoriesEntity WHERE unique_id = :id OR unique_id IN (SELECT linked_id FROM hibernate.entity.CallDetailHistoriesEntity WHERE unique_id = :id)]
    at org.hibernate.QueryException.generateQueryException(QueryException.java:120)
    at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
    at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:545)
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:654)
    ... 41 more
Caused by: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode 
 \-[IDENT] IdentNode: 'linked_id' {originalText=linked_id}

    at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:160)
    at org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:991)
    at org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:759)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:675)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:4918)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4819)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4486)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2134)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2087)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:607)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
    ... 47 more

///////////////////////////////////// My 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 that = (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 any property named linked_id . It has one named linkedId , though. That's thus what you should use in your JPQL query.

I would also strongly advise to stick to Java naming conventions: variables and methods never have an underscore in Java, and use camelCase. So I would also renamed unique_id to uniqueId , source_caller_id to sourceCallerId , etc. Of course, the getters and the query should be changed accordingly.

The next step is to realize that the whole point of JPA/Hibernate is to have a graph of entities, interconnected using associations. So you should most probaby not have a linkedId attribute of type String in the entity, but rather a ManyToOne or OneToOne association to another entity. That's what allwos navigating to the graph of entities in your code, and using joins in your queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM