Codec not found for requested operation: [date <-> java.util.Date] exception in Cassandra

I was trying to create an Accessor interface in a Java application communicating with cassandra. The interface looked something like this:

import java.util.Date;

import com.datastax.driver.mapping.Result;
import com.datastax.driver.mapping.annotations.Accessor;
import com.datastax.driver.mapping.annotations.Query;
import com.custom.package.Order;

@Accessor
public interface OrderAccessor {

    @Query("SELECT * FROM orders WHERE checkout_date = ?")
    Result<Order> findAllOrdersByCheckoutDate(Date checkoutDate);

}

When I was trying to run the query, I got the following exception:

Codec not found for requested operation: [date <-> java.util.Date]

It turned out that for the Cassandra date type, the correct Java type to use is com.datastax.driver.core.LocalDate

Changing my java.util.Date to this resolved the issue.

Retrieve records older than a specified amount of time in Laravel

You can use the Carbon library to easily create an eloquent query that will filter the records based on a given amount of elapsed time.

Let’s see an example where clause which gives us the records that are at most 4 weeks old:

<?php

Messages::where('created_by', '>=', Carbon::now()->subWeeks(4)->toDateTimeString());

This example was tested in Laravel 5.2.