native query, why I got hashmap instead of an entity

85 views
Skip to first unread message

George Wu

unread,
Aug 16, 2016, 1:45:43 AM8/16/16
to kundera...@googlegroups.com

The code is quite simple:


    public WaySearchPlaceMessage find(EntityManager em, String search_id) {
        String sq = "select * from way_search_place_message where id = ?1";
        sq = Text.replaceQueryParam(sq, 1, search_id);
        javax.persistence.Query q = em.createNativeQuery(sq, WaySearchPlaceMessage.class);
        List<WaySearchPlaceMessage> ls = q.getResultList();
        return ls.size() > 0 ? ls.get(0) : null;
    }

the return type is an entity. in runtime the returned type is a hashmap.
Then it throws a runtime ClassCastException exception.

Can anybody help me?
Thanks a lot.

George Wu

///

exception: java.lang.ClassCastException: java.util.HashMap cannot be cast to cn.x8p.db.entity.place.WaySearchPlaceMessage
        at cn.x8p.sql.place.message.result.Update.find(Update.java:45)
        at cn.x8p.sql.place.message.list.Geohash.search(Geohash.java:62)

George Wu

unread,
Aug 16, 2016, 9:31:47 PM8/16/16
to kundera...@googlegroups.com
By the way, I am using cassandra thrift driver.
When I enumerate the entity list, I got hashmap instead of the entity type.

George Wu

--
You received this message because you are subscribed to the Google Groups "kundera-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kundera-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Devender Yadav

unread,
Sep 26, 2016, 11:28:28 AM9/26/16
to kundera-discuss
Hi George,


I apologize for replying late. Are you still facing this issue?
To unsubscribe from this group and stop receiving emails from it, send an email to kundera-discu...@googlegroups.com.

George Wu

unread,
Apr 19, 2017, 11:20:22 PM4/19/17
to kundera...@googlegroups.com
Still problem. just test it:
kundera 3.8, cassandra 3.10
the for loop will throw exception:

            public List<map_webcast_vote_option> findByQuestion(EntityManager em, String id) {
                String sq = "select * from map_webcast_vote_option where question_message_id = ?1";
                sq = Text.replaceQueryParam(sq, 1, id);
                Query q = em.createNativeQuery(sq, map_webcast_vote_question.class);
                List<map_webcast_vote_option> ls = q.getResultList();
                for (map_webcast_vote_option a : ls) {
                }
                return ls;
            }


create table map_webcast_vote_option (
    id timeuuid,
    question_message_id timeuuid,
    to_webcast_id timeuuid, 
    question_code varchar,
    code varchar,

    description text, 
    vote_count bigint, 
    primary key (id)
);
create index map_webcast_vote_option__to_webcast_id
    on map_webcast_vote_option (to_webcast_id);
create index map_webcast_vote_option__question_message_id
    on map_webcast_vote_option (question_message_id);




[2017-04-20T10:26:21.240+0800] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=29 _
ThreadName=Thread-3] [timeMillis: 1492655181240] [levelValue: 800] [[
  10:26:21.240 [http-listener-2(4)] WARN  c.i.c.c.d.CassandraDataHandlerBase - E
rror while setting fieldcode value via CQL, Caused by: .
com.impetus.kundera.property.PropertyAccessException: java.lang.IllegalArgumentE
xception: Can not set java.lang.String field cn.x8p.map.entity.db.webcast.map_we
bcast_vote_question.code to java.util.HashMap
        at com.impetus.kundera.property.PropertyAccessorHelper.set(PropertyAcces
sorHelper.java:110) ~[kundera-core-3.8.jar:na]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.set
FieldValueViaCQL(CassandraDataHandlerBase.java:1509) [kundera-cassandra-3.8.jar:
na]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.pop
ulateViaThrift(CassandraDataHandlerBase.java:1163) [kundera-cassandra-3.8.jar:na
]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.onC
olumn(CassandraDataHandlerBase.java:1054) [kundera-cassandra-3.8.jar:na]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.pop
ulateEntity(CassandraDataHandlerBase.java:653) [kundera-cassandra-3.8.jar:na]
        at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQue
ry(CassandraClientBase.java:2301) [kundera-cassandra-3.8.jar:na]
        at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(C






Caused by: java.lang.IllegalArgumentException: Can not set java.util.UUID field
cn.x8p.map.entity.db.webcast.map_webcast_vote_question.to_webcast_id to java.uti
l.HashMap
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(
UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_40]
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(
UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_40]









To unsubscribe from this group and stop receiving emails from it, send an email to kundera-discuss+unsubscribe@googlegroups.com.

George Wu

unread,
Apr 20, 2017, 12:44:19 AM4/20/17
to kundera...@googlegroups.com
Sorry, it is due to a bug in my test code.
It works now.



            public List<map_webcast_vote_option> findByQuestion(EntityManager em, String id) {
                String sq = "select * from map_webcast_vote_option where question_message_id = ?1";
                sq = Text.replaceQueryParam(sq, 1, id);
                Query q = em.createNativeQuery(sq, map_webcast_vote_option.class);

Devender Yadav

unread,
Apr 20, 2017, 1:15:13 AM4/20/17
to kundera...@googlegroups.com
Ok George.

Let me know if you face any other issue.
Reply all
Reply to author
Forward
0 new messages