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

Add support for entity updates before save using EntityCallbacks [DATACASS-618] #786

Closed
spring-projects-issues opened this issue Jan 4, 2019 · 3 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 4, 2019

Rami Del Toro opened DATACASS-618 and commented

I have a CassandraEventListener extends AbstractCassandraEventListener whitch modifies the entity in the onBeforeSave method.

While the entity is modified, the modification is not saved in Cassandra. During debug, it was found because of the following:

 

  • In CassandraTemplate.java

Insert insert = QueryUtils.createInsertQuery(tableName.toCql(), entity, options, this.getConverter(), persistentEntity);

this.maybeEmitEvent(new BeforeSaveEvent(entity, tableName, insert));

 

The CQL Insert statement creates the statement first with existing entity and THEN executes the onBeforeSave. However, the rest of the flow will use the insert statement that was already created thus not being able to use the new version of the entity.


Issue Links:

  • DATACMNS-1467 Add API for entity callbacks/change before save/after load
    ("depends on")
  • DATACASS-4 Implement Auditing
    ("is depended on by")

Referenced from: commits 8f6d070, 0d11ba7, 9de890c, 1efbcc7

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 7, 2019

Mark Paluch commented

This is expected behavior. BeforeSaveEvent is fired right before executing the Statement. We probably should introduce BeforeConvertEvent to reflect event-based entity changes in the INSERT/UPDATE statement.

BeforeSaveEvent gives you access to a statement. We're considering a generic entity callback API that expresses entity mutation support. Right now, events are immutable and if the entity class is immutable as well, there would be no chance of updating an entity prior to saving.

Let me turn this ticket into an enhancement

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 7, 2019

Rami Del Toro commented

Thanks Mark. Do you perhaps have any suggestions on what options would be available as of now?

Basically, I would want to modify the entity prior in saving and right after it is read. Need this to do application controlled encryption on fields

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 8, 2019

Mark Paluch commented

You could mark the properties as transient and include the encrypted assignment in the Insert/Update object that you get via BeforeSaveEvent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants