Skip to content

@ReadOnlyProperty with child entity associated with a View possibly related to DATAJDBC-431 #1249

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

Closed
davidbruce opened this issue May 17, 2022 · 4 comments
Assignees
Labels
status: feedback-provided Feedback has been provided type: bug A general bug

Comments

@davidbruce
Copy link

Hello, I am using spring-data-relational 2.2.11 with Postgres and I am having an issue where I have a child @Column that maps to a different Java class that is annotated with @Table and that table is a view.

This works fine for retrieval, but for some reason when I attempt to modify the parent and use parentNameRepository.save(), it attempts to run a delete statement against the child. This then throws an error because it is attempting to delete from a view. @ReadOnlyProperty does not appear to prevent this delete statement and neither does annotation the child class with @Immutable.

For now the our work are either to create triggers at the DB level that ignores this delete generated delete statement, or just iterate over the parent and set a @Transient field with a repository call for the view. (not ideal).

I found that there was an old ticket for ignored @ReadOnlyProperty DATAJDBC-431

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 17, 2022
@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 17, 2022
@schauder
Copy link
Contributor

Please clarify which property is annotated with @ReadOnlyProperty.

class A {
    @ReadOnlyProperty // the complete reference is read only
    B b;
}
class B {
    @ReadOnlyProperty // only one property of the referenced class is read only
     String someProperty
}

@schauder schauder added the status: waiting-for-feedback We need additional information before we can continue label May 18, 2022
@schauder schauder self-assigned this May 18, 2022
schauder added a commit that referenced this issue May 18, 2022
The `@ReadOnlyProperty` annotation is now honoured for references to entities or collections of entities.

For tables mapped to such annotated references, no insert, delete or update statements will be created.
The user has to maintain that data through some other means.
These could be triggers or external process or `ON DELETE CASCADE` configuration in the database schema.

See #1249
schauder added a commit that referenced this issue May 18, 2022
@davidbruce
Copy link
Author

@schauder The complete reference is marked with @ReadOnlyProperty.

@Table("parent")
class ParentEntity {
    @Id
    UUID id;
    String timezone; 
    String starttime;
    String endtime;
    boolean enabled;
    @ReadOnlyProperty
    @Column("parent_id")
    ChildViewEntity childViewEntity;
}

@Table("child_view")
class ChildViewEntity {
    int calculatedField;
}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 18, 2022
schauder added a commit that referenced this issue May 19, 2022
The `@ReadOnlyProperty` annotation is now honoured for references to entities or collections of entities.

For tables mapped to such annotated references, no insert, delete or update statements will be created.
The user has to maintain that data through some other means.
These could be triggers or external process or `ON DELETE CASCADE` configuration in the database schema.

Closes #1249
schauder added a commit that referenced this issue May 19, 2022
Refactoring.

See #1249
@schauder
Copy link
Contributor

Thanks.
I addressed that in a PR.

It would be great, if you could verify that it solves the problem for you.

@davidbruce
Copy link
Author

@schauder I've tested your change and verified it has solved our problem. Thank you very much for looking into this. When will this officially release?

schauder added a commit that referenced this issue May 23, 2022
Refactoring and code aesthetics.

See #1249
Original pull request #1250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants