Pushed DATACASS-107, initial support for repository query methods

133 views
Skip to first unread message

Matthew Adams

unread,
Mar 5, 2014, 3:11:51 PM3/5/14
to spring-dat...@googlegroups.com
I just pushed the changes for DATACASS-107, which adds basic support for query methods on repositories.

Named queries and @Query-annotated methods are supported.  Queries derived from query method names are not yet supported.

-matthew

Colin McQueen

unread,
Mar 17, 2014, 8:33:14 AM3/17/14
to spring-dat...@googlegroups.com
Using the @Query annotation, do you use same syntax in CQL with the table and column names or is it like JPA where you can use your class and field names?

Matthew Adams

unread,
Mar 17, 2014, 8:38:47 AM3/17/14
to spring-dat...@googlegroups.com
The @Query annotation accepts only pure CQL.  It is not like JPA, or intended to be so.  You must use table & column names.

-matthew


--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cass...@googlegroups.com.
To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.
To view this discussion on the web visit https://groups.google.com/d/msgid/spring-data-cassandra/ff366c33-d1a0-4689-8317-216dcbea7cdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
mailto:mat...@matthewadams.me 

Colin McQueen

unread,
Mar 18, 2014, 9:12:40 AM3/18/14
to spring-dat...@googlegroups.com
Would this example work?

@Query("INSERT INTO foo VALUES (?1) USING TTL ?2")
Foo insertWithTimeToLive(final Foo entity, final int timeToLive);

Basically the goal is to save all the data in the entity with an expiry time. I plan to write an update method as well and have a custom save method that will figure out if it should call the repository insert or update method.

On Monday, March 17, 2014 9:38:47 AM UTC-3, Matthew Adams wrote:
The @Query annotation accepts only pure CQL.  It is not like JPA, or intended to be so.  You must use table & column names.

-matthew
On Mon, Mar 17, 2014 at 7:33 AM, Colin McQueen <colin....@shiftenergy.com> wrote:
Using the @Query annotation, do you use same syntax in CQL with the table and column names or is it like JPA where you can use your class and field names?

On Wednesday, March 5, 2014 4:11:51 PM UTC-4, Matthew Adams wrote:
I just pushed the changes for DATACASS-107, which adds basic support for query methods on repositories.

Named queries and @Query-annotated methods are supported.  Queries derived from query method names are not yet supported.

-matthew

--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cassandra+unsub...@googlegroups.com.

Colin McQueen

unread,
Mar 19, 2014, 10:48:12 AM3/19/14
to spring-dat...@googlegroups.com
So I tried the above query and it failed. So I put all my entity values in the parameter list (11 columns plus the TTL) and it still failed.

Here is the error:
java.lang.IllegalArgumentException: encountered unsupported query parameter types [class java.lang.Integer,int] 

Don't understand why integers are not supported. 

Matthew Adams

unread,
Mar 18, 2014, 10:52:03 AM3/18/14
to Colin McQueen, spring-dat...@googlegroups.com
I don't think that'll work.  You're binding an instance of Foo to ?1, but the positional parameter placeholders are intended to be for fields/properties.

As for your use of TTL, I think we need a better way of supporting that.  All of the generated repository interfaces delegate to CassandraTemplate, and I don't see any options in CassandraTemplate that let you specify TTL.  Please enter an issue requesting that the insert* methods & repository save* methods include the capability of specifying TTL (and any other options that are appropriate).

-matthew


To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cass...@googlegroups.com.

To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.

For more options, visit https://groups.google.com/d/optout.



--

Colin McQueen

unread,
Mar 21, 2014, 6:35:25 AM3/21/14
to spring-dat...@googlegroups.com, Colin McQueen
Thanks. I created a task in JIRA: https://jira.spring.io/browse/DATACASS-114


On Tuesday, March 18, 2014 11:52:03 AM UTC-3, Matthew Adams wrote:
I don't think that'll work.  You're binding an instance of Foo to ?1, but the positional parameter placeholders are intended to be for fields/properties.

As for your use of TTL, I think we need a better way of supporting that.  All of the generated repository interfaces delegate to CassandraTemplate, and I don't see any options in CassandraTemplate that let you specify TTL.  Please enter an issue requesting that the insert* methods & repository save* methods include the capability of specifying TTL (and any other options that are appropriate).

-matthew
On Tue, Mar 18, 2014 at 8:12 AM, Colin McQueen <colin....@shiftenergy.com> wrote:
Would this example work?

@Query("INSERT INTO foo VALUES (?1) USING TTL ?2")
Foo insertWithTimeToLive(final Foo entity, final int timeToLive);

Basically the goal is to save all the data in the entity with an expiry time. I plan to write an update method as well and have a custom save method that will figure out if it should call the repository insert or update method.

On Monday, March 17, 2014 9:38:47 AM UTC-3, Matthew Adams wrote:
The @Query annotation accepts only pure CQL.  It is not like JPA, or intended to be so.  You must use table & column names.

-matthew
On Mon, Mar 17, 2014 at 7:33 AM, Colin McQueen <colin....@shiftenergy.com> wrote:
Using the @Query annotation, do you use same syntax in CQL with the table and column names or is it like JPA where you can use your class and field names?

On Wednesday, March 5, 2014 4:11:51 PM UTC-4, Matthew Adams wrote:
I just pushed the changes for DATACASS-107, which adds basic support for query methods on repositories.

Named queries and @Query-annotated methods are supported.  Queries derived from query method names are not yet supported.

-matthew

--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cassandra+unsubscri...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cassandra+unsub...@googlegroups.com.
To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.



--

Colin McQueen

unread,
Mar 26, 2014, 10:21:34 AM3/26/14
to spring-dat...@googlegroups.com, Colin McQueen
I think I found another bug. I am trying to find data by partition key vs the whole key that includes the cluster key and I wrote the following query:

@Query(SELECT * FROM foo WHERE p1 = :p1 AND p2 = :p2 AND p3 = :p3)
Set<Foo> findByPartitionKey(@Param("p1") final double p1, @Param("p2") final double p2, @Param("p3") final String p3); 

This gives the following stacktrace:

com.datastax.driver.core.exceptions.InvalidQueryException: Invalid amount of bind variables
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:269)
at com.datastax.driver.core.ResultSetFuture.getUninterruptibly(ResultSetFuture.java:183)
at com.datastax.driver.core.Session.execute(Session.java:111)
at org.springframework.cassandra.core.CqlTemplate$12.doInSession(CqlTemplate.java:519)
at org.springframework.cassandra.core.CqlTemplate$12.doInSession(CqlTemplate.java:510)
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:487)
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:510)
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:499)
at org.springframework.cassandra.core.CqlTemplate.query(CqlTemplate.java:409)
at org.springframework.cassandra.core.CqlTemplate.query(CqlTemplate.java:436)
at org.springframework.cassandra.core.CqlTemplate.query(CqlTemplate.java:430)
at org.springframework.data.cassandra.repository.query.AbstractCassandraQuery.execute(AbstractCassandraQuery.java:122)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy1408.findByPartitionKey(Unknown Source) 

I tried using the numbers instead of bind parameter names but that gave me an IndexOutOfBoundsException on getParametersWithIndex in the StringBasedCassandraQuery class.
Reply all
Reply to author
Forward
0 new messages