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

Persist fails on entity without id and version field if @EnableAuditing [DATACMNS-957] #1412

Closed
spring-projects-issues opened this issue Dec 13, 2016 · 1 comment
Assignees
Labels
type: bug
Milestone

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Dec 13, 2016

Walery Strauch opened DATACMNS-957 and commented

Follow domain should be persist:

public class Domain {

    String field;
}

It works, as long as auditing is turned off. After putting @EnableAuditing to application follows exception is thrown:

org.springframework.data.mapping.model.MappingException: Cannot determine IsNewStrategy for type class codes.walery.spring.mongo.audit.DomainWithoutAuditing!

Description:

If auditing is enabled those steps are executed:

  1. Determine strategy to fill auditing fields
  2. Find fields that should be filled via auditing
  3. Fill found fields

If strategy can't be determined (because id and version is not available in domain) exception is thrown and object isn't persisted.

This exception is also thrown if you don't have any fields in model that are filled via auditing.
There is no need to throw this exception if no fields are filled via auditing.

Some code to make it clear:

// Everything fine
public class Domain1 {

    @Id
    Long id;

    @LastModifiedDate
    LocalDateTime lastModifiedDate;

    String field;
}
// Exception is thrown. This is correct, there is no way to know how to fill lastModifiedDate field.
public class Domain2 {

    @LastModifiedDate
    LocalDateTime lastModifiedDate;

    String field;
}
// Exception is thrown. But there is no reason for Exception.
public class Domain3 {

    String field;
}

I've patch for this ticket.
PR: #189


Issue Links:

  • DATAMONGO-1592 Adapt AuditingEventListenerUnitTests after changes in core auditing

Referenced from: pull request #189

Backported to: 1.13 GA (Ingalls), 1.12.7 (Hopper SR7), 1.11.7 (Gosling SR7)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 13, 2016

Oliver Drotbohm commented

Care to elaborate why it makes sense to use an entity without an identifier property in the first place? The exception is in place to basically prevent accidental misconfiguration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants