Comments (16)
You mean that given a @NotNull
annotation, Achilles should set an empty collection to an entity when reading null columns from Cassandra isn't it ?
from achilles.
I suppose it is reasonable.
from achilles.
Be aware that setting @NotNull
will also trigger validation on the collection when you persist the entity (provided you activate Bean validation).
I prefer to keep the @NotNull
annotation for Bean Validation and create another one to inject empty collections/maps when deserializing data from Cassandra. Maybe @EmptyCollectionIfNull
or something similar (any suggestion for a better name is welcomed).
It is better to separate both concerns and do not mix them
from achilles.
The simple case is : domain object has an empty set, the validation takes place on persist and it persists well - if I find a value, change any other value - I have to set empty collection instead of nulls - and all that null checks will be over the code.
from achilles.
"if I find a value, change any other value - I have to set empty collection instead of nulls - and all that null checks will be over the code."
In this case, I can make @EmptyCollectionIfNull
apply both on persist/update and on load
from achilles.
Interestingly, @EmptyCollectionIfNull
can be coded as a built-in interceptor that takes place before Bean Validation
from achilles.
I don't like to introduce one more annotation while @NotNull in this case means the same
from achilles.
Or I can make deserializing null into empty collections as default behavior in Achilles. This way, no need to introduce an extra annotation
from achilles.
My point is
- default behavior in Achilles is null values for collections
- if there is a @NotNull or @EmptyCollectionIfNull provides empty collection (new HashSet<> neither Collections.emptySet() )
from achilles.
Ok, I would go with @EmptyCollectionIfNull. @NotNull will force people to pull Bean Validation jar dependency even though they do not want to use Bean Validation
from achilles.
I've just check, the default behavior of the Java Driver is to return an empty collection or map if the value coming from Cassandra is null: https://github.com/datastax/java-driver/blob/2.0/driver-core/src/main/java/com/datastax/driver/core/ArrayBackedRow.java#L254
Since Achilles gets value from the Java Driver, there is nothing to do indeed ...
I've written an IT to confirm it:
@Test
public void should_test_not_null_collections() throws Exception {
//Given
CompleteBean entity = CompleteBeanTestBuilder.builder().id(10L).name("name").buid();
manager.persist(entity);
//When
final Row row = manager.getNativeSession().execute("SELECT * FROM CompleteBean WHERE id=?", 10L).one();
//Then
final List<String> friends = row.getList("friends", String.class);
assertThat(friends).isNotNull().isEmpty();
final Set<String> followers = row.getSet("followers", String.class);
assertThat(followers).isNotNull().isEmpty();
final Map<Integer, String> preferences = row.getMap("preferences", Integer.class, String.class);
assertThat(preferences).isNotNull().isEmpty();
}
This issue can be closed.
from achilles.
I think the bug has to be reopened:
my code:
getPersistenceManager().typedQuery(MyEntity.class, "SELECT * from myentity;").get();
TypedQueryBuilder.get : 79
T entity = mapper.mapRowToEntityWithPrimaryKey(meta, row, propertiesMap, managed);
EntityMapper.mapRowToEntityWithPrimaryKey : 71
Object value = cqlRowInvoker.invokeOnRowForFields(row, pm);
RowMethodInvoker.invokeOnRowForFields : 41
if (row != null && !row.isNull(propertyName)) {
com.datastax.driver.core.ArrayBackedRow.isNull : 56
return isNull(metadata.getFirstIdx(name));
com.datastax.driver.core.ArrayBackedRow.isNull : 52
return data.get(i) == null;
based on the data it returns NULL -> therefore entity is NOT populated with non-null set/list/map
from achilles.
You're right, the check in done in Achilles
On Tue, Apr 29, 2014 at 10:31 AM, Vladimir Dolzhenko <
[email protected]> wrote:
I think that the bug has to be reopened:
TypedQueryBuilder.get : 79
T entity = mapper.mapRowToEntityWithPrimaryKey(meta, row, propertiesMap,
managed);EntityMapper.mapRowToEntityWithPrimaryKey : 71
Object value = cqlRowInvoker.invokeOnRowForFields(row, pm);RowMethodInvoker.invokeOnRowForFields : 41
if (row != null && !row.isNull(propertyName)) {com.datastax.driver.core.ArrayBackedRow.isNull : 56
return isNull(metadata.getFirstIdx(name));com.datastax.driver.core.ArrayBackedRow.isNull : 52
return data.get(i) == null;based on the data it returns NULL -> therefore entity is NOT populated
with non-null set/list/map—
Reply to this email directly or view it on GitHubhttps://github.com//issues/53#issuecomment-41652516
.
from achilles.
btw, I didn't find your IT in code - have you committed it ?
from achilles.
Nope, I did not commit the IT since it was for checking only. But I'll definitely add new IT to cover the @EmptyCollectionIfNull case
from achilles.
Done. Add unit and integration tests too
from achilles.
Related Issues (20)
- Achilles Junit: NoClassDefFoundError: com/codahale/metrics/JmxReporter HOT 23
- Schema validation fails for UDT when keyspace name is in Uppercase HOT 6
- initSession should use supplier instead HOT 1
- Getting "info.archinnov.achilles.exception.AchillesTranscodingException: com.fasterxml.jackson.databind.JsonMappingException" while reading the JSON from Cassandra DB HOT 5
- Achilles can't deserialize undefined field into primitive HOT 4
- prepared statements cache size issues in cassandra logs HOT 34
- Need a way to reset Statement cache for test HOT 1
- Add the ability to set the JMX port
- Jackson version is not updated in Maven repo HOT 11
- Multiple AbstractCQLCompatibleType & FunctionCall for token function HOT 17
- Does achilles generate delete implicitly on insert ?? HOT 1
- [feature] Java 11 Builds HOT 2
- Is it possible to have Achilles add an @Generated annotation? HOT 2
- Java driver 4.x compatibility HOT 17
- Inheritance not working with Entity
- Exception on OpenJDK 15 HOT 3
- Configurable protocol version HOT 2
- Bulk Insert/Update Operation HOT 2
- Achilles embedded cassandra throws Java.lang.noSuchFieldError : num_tokens
- missing classes java 17 : info.archinnov.achilles.generated.ManagerFactory
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from achilles.