valchkou / cassandra-driver-mapping

JPA addon for DataStax Java Driver for Cassandra
58 stars 24 forks source link

@Ttl not being passed on table creation #38

Closed DBatOWL closed 9 years ago

DBatOWL commented 9 years ago

Using the @Ttl annotation on a table, while the table gets created, when I check the default_time_to_live value on the table it's always 0, the value I provided does not get set. Has this been implemented yet?

valchkou commented 9 years ago

That's correct, this is by design.

@TTL on table does not modify table property: default_time_to_live. Table properties you can set with special annotation @TableProperty. see sample: https://github.com/valchkou/cassandra-driver-mapping#mapping_properties

Table properties are not alterable. Ones you create table with @TableProperty('default_time_to_live') you will have to manually alter table if you ever need change the value or get rid of default ttl at all.

@Ttl is more dynamic in turn. It applied to CQL statement on every save(). You can't see it but it works. If you change or remove @Ttl on entity it will take effect on the next restart automatically (or unles you force refresh with EntityTypeParser.removeAll() or EntityTypeParser.remove(Entity.class);).

does it make sense?

DBatOWL commented 9 years ago

Thanks!

I guess where I get lost is when I see in the doc "default TTL for the entity" and it was on the table definition, I thought it was the table setting. Since the next line of the doc says "You can override default TTL at at time when you save entity", these two lines seem to match how I would apply a different TTL in CQL, i.e. table property and override.

So if I understand it correctly, there are 3 ways to control TTL on entities, first is by setting a default for the table (set by the @TableProperty) and there's a special one used by the API (set by @Ttl) that overrides the table property on every save and finally a user can specifically override those values at save time.

Based on your answer I take it you would suggest using the @Ttl annotation as it is much more flexible. If that is true, maybe you could provide some the details from your answer in the doc as it makes it clearer how this is added flexibility that could make developer's/DBA's lives simpler.

valchkou commented 9 years ago

Agree, the way how I described it is misleading. I should think of rephrasing it.

valchkou commented 9 years ago

explained in readme