0

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;
    }
}
5
  • Show the relevant entities. And use aliases in your query: select p from Product p where p.name = ... Commented Nov 10, 2016 at 18:00
  • Yes, but it's a different query, using different entities. So it's irrelevant. Commented Nov 10, 2016 at 23:11
  • Oh, sorry, my mistake. SELECT FROM My_Table WHERE unique_id = 1 OR unique_id IN (SELECT linked_id FROM My_Table WHERE unique_id = 1) Is working well. (SAme Table). Commented Nov 10, 2016 at 23:41
  • The table does not matter. The query in your question uses the entity CallDetailHistoriesEntity. The query in your question uses the entity My_Table. Those are not the same entities. Post the code of CallDetailHistoriesEntity. Commented Nov 11, 2016 at 7:50
  • Edited......... Commented Nov 11, 2016 at 9:30

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.