0

I am trying to use blaze persistence UpdatableEntityView as the request body with spring boot. Following is the code for UpdatableEntityView

@UpdatableEntityView
@EntityView(DealListing.class)
public interface DealListingUpdateView {
    @IdMapping
    Long getId();
    void setId(Long id);

    Instant getListedOn();
    void setListedOn(Instant listedOn);
}

Following is the rest controller mapping

@PutMapping("/deal-listings/sell/{id}")
    public void test(@PathVariable Long id, @RequestBody DealListingUpdateView dealListingUpdateView){
        dealListingService.testUpdate(id, dealListingUpdateView);
}

Following is the pom.xml dependency to do the deserialization as specified in the blaze persistence document

        <dependency>
            <groupId>com.blazebit</groupId>
            <artifactId>blaze-persistence-integration-jackson</artifactId>
            <scope>compile</scope>
        </dependency>

But when i submit the request i am getting the following error

Type definition error: [simple type, class com.ilex.tradeservice.domain.view.blaze.DealListingUpdateView]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.ilex.tradeservice.domain.view.blaze.DealListingUpdateView` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 1]

Mayuran
  • 669
  • 2
  • 8
  • 39

1 Answers1

1

As you can see in the documentation, you will need the Spring Data WebMvc integration: https://persistence.blazebit.com/documentation/1.6/entity-view/manual/en_US/index.html#spring-data-webmvc-integration

You will also have to additionally annotate your controller parameter with @EntityViewId("id")

@PutMapping("/deal-listings/sell/{id}")
public void test(@PathVariable Long id, @EntityViewId("id") @RequestBody DealListingUpdateView dealListingUpdateView){
        dealListingService.testUpdate(id, dealListingUpdateView);
}
Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • Thank you for the suggestion, i did this but after adding this dependency i am getting some exception so i have removed it. Let me add and study the exception again to understand what is going wrong. – Mayuran Feb 14 '22 at 01:00
  • If you can share some details I can maybe help you, but you can also try one of the quickstarts to compare what you might be missing: https://github.com/Blazebit/blaze-persistence#quickstart – Christian Beikov Feb 14 '22 at 09:26
  • I managed to make it work. Just putting here so it may help others. Actually i missed the following dependency. com.blazebit blaze-persistence-integration-spring-data-2.4 compile By the way i noticed that when update happens its not triggering the hibernate/jpa callback events such as PreUpdate/PrePersist. Is it expected? – Mayuran Feb 22 '22 at 07:27
  • That is expected for the `QUERY` flush strategy, which is the default. You can switch to `@UpdatableEntityView(strategy = FlushStrategy.ENTITY)` if you need entity listeners to be called for update/remove operations, but this comes with a performance cost, so maybe you can make use of entity view listeners instead: https://persistence.blazebit.com/documentation/1.6/entity-view/manual/en_US/index.html#lifecycle-and-listeners – Christian Beikov Feb 22 '22 at 08:43