Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cql can't map PK right to entity by using kunder2.4 + cassandra1.2.2 !!!!!!! #214

Closed
zhouhero opened this issue Mar 14, 2013 · 14 comments
Closed
Milestone

Comments

@zhouhero
Copy link

I used the following cql to search the data, the PK column is not right mapping to entity class.


select * from test1 where key in (1,2,3)

by the way, the table is created not by cassandra-cli not by cql.
It very important to me ,can anyone help me?

@mevivs
Copy link
Collaborator

mevivs commented Mar 14, 2013

Hi,
Can you please a bit more on this?

-Vivek

@mevivs
Copy link
Collaborator

mevivs commented Mar 14, 2013

Looking for more description around this, please provide it.

-Vivek

@zhouhero
Copy link
Author

  • My Table:
    create column family test with comparator = UTF8Type and key_validation_class=Int32Type and column_metadata =
    [
    {column_name:userid, validation_class:UUIDType}
    {column_name:url, validation_class:UTF8Type}
    {column_name:datetime, validation_class:DateType}
    {column_name:linkcount, validation_class:Int32Type}
    ];

  • My Entity:
    @entity
    @table(name = "test", schema = XXXXX)
    @XmlRootElement(name = "TestEntity")
    public class TestEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @id
    @column(name = "id")
    private int id;

    @column(name = "userid")
    private UUID userid;

    @column(name = "url")
    private String url;

    @column(name = "datetime")
    private Timestamp datetime;

    @column(name = "linkcounts")
    private int linkcounts;
    ...
    ...
    ...

  • My test program:

TestEntity test1 = new TestEntity();
test1.setId(1);
test1.setUrl("1");

entityManager.persist(test1);
entityManager.flush();

TestEntity test2 = new TestEntity();
test2.setId(2);
test2.setUrl("2");
entityManager.persist(test2);
entityManager.flush();

TestEntity test3 = new TestEntity();
test3.setId(3);
test3.setUrl("3");
entityManager.persist(test3);
entityManager.flush();

String cql = "select * from test where key in (1,2,3)";

Query query = entityManager.createNativeQuery(cql, TestEntity.class);
List list = (List) query.getResultList();

if (list != null) {
for (TestEntity e : list) {
System.out.println(e.getId());
}
}

  • RESULT:
    the output of e.getId() is always 0!

@zhouhero
Copy link
Author

can you help me check this problem?

@mevivs
Copy link
Collaborator

mevivs commented Mar 15, 2013

Yes.. i am looking into this.

-Vivek

@zhouhero
Copy link
Author

by the way, not only "in" keyword, the normal cql searching can not do well .
like:
"select * from test where key =1";

@mevivs
Copy link
Collaborator

mevivs commented Mar 15, 2013

Hi,
I have looked into this issue. As a workaround If you change:

@Id
@Column(name = "id")
private int id;

as

@Id
@Column(name = "key")
private int id;

It should work. I will have a look and will provide a proper fix for this.

-Vivek

@zhouhero
Copy link
Author

thanks for your idea,
i have done it like you said also,
it can does well now.
but this is a bug need to fix , i think.

@mevivs
Copy link
Collaborator

mevivs commented Mar 15, 2013

This can be computed implicitly. With Cassandra 1.2 onwards CQL3 does not return id field as key with CqlRow object, but as a column with a name "key"(Earlier it was not the case).I did post some queries around this on cassandra user community. So if you give column name as "key" it will work.

Though name of column attribute annotated with @column annotation is irrelevant as Cassandra does not use this name as a row key name(it is not possible to define a name for row key in cassandra). So such computations are done within Kundera. I will get it done but i don't see a much of value add with this.

Hope it clarifies the cause behind this issue.

-Vivek

@zhouhero
Copy link
Author

by the way ,
when i creat table like fellow , i think the pk column name is return to "id" not "key" by cql

create columnfamily test (id int primary key, url text, userid uuid, datetime timestamp, linkcounts int);

@zhouhero
Copy link
Author

at this time, the pk name should like fellow, i think. is it right?
@column(name = "id")

@mevivs
Copy link
Collaborator

mevivs commented Mar 15, 2013

yes. i see your point , it should not be an issue after interoperability support b/w cql and thrift.(planned for 2.5)

@zhouhero
Copy link
Author

thank you very much,
when will kundera 2.5 release?

@mevivs
Copy link
Collaborator

mevivs commented Apr 29, 2013

Releasing with 2.5, please verify.

-Vivek

@mevivs mevivs closed this as completed Jul 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants