question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation is not working on Spring REST Data on Native

See original GitHub issue

Describe the bug Spring REST Data extension stopped working when using validations in Native.

This is a regression issue caused by this commit: https://github.com/quarkusio/quarkus/commit/8c76e39060f6b288eaaeeb28bc477b33a972a40f.

This is how my Spring endpoint looks like:

@RepositoryRestResource(exported=false, path = "books", collectionResourceRel = "books")
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {

    @Override
    @RestResource(exported = true)
    Page<Book> findAll(Pageable pageable);

    @RestResource(exported = true)
    List<Book> findByOrderByNameDesc();

    @Override
    @RestResource(path = "id")
    Optional<Book> findById(Long id);

    @Override
    @RestResource
    Book save(Book book);
}

And my entity:

@Entity
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Length(min = 2, max = 50, message = "length must be between {min} and {max}")
    @NotBlank(message = "Name may not be blank")
    private String name;

    @Length(min = 2, max = 50, message = "length must be between {min} and {max}")
    @NotBlank(message = "Author may not be blank")
    private String author;

    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "library_id")
    private Library library;
// ...

When calling a POST/PUT endpoint and the validation fails, the endpoint fails with Internal Server Error:

Internal Server Error - Error id 7839b916-3415-4673-8059-572770e26c35-1

Expectation is that it should return the constraint violations. Note that the same is working fine in JVM. I’ve reverted the above commit and everything works in JVM and Native.

To Reproduce

1- git clone https://github.com/Sgitario/beefy-scenarios 2- git checkout reproducer_15409 3- cd beefy-scenarios/602-spring-data-rest 4- mvn clean verify -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-native-image:21.0.0-java11 -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.native-image-xmx=4g (it needs to have built quarkus master locally)

Environment (please complete the following information): Quarkus version or git rev: 999-SNAPSHOT (1.12.1.Final)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
rsvobodacommented, Mar 2, 2021

We can prepare https://github.com/quarkusio/quarkus-ecosystem-ci integration. This way you will get GH notifications directly?

0reactions
Sgitariocommented, Mar 5, 2021

Now, Spring REST Data works similarly as in Panache REST. Now, services return 400 when there are violations. Fixed as part of https://github.com/quarkusio/quarkus/pull/15447.

However, when there is a violation, no message is returned. Reported in https://github.com/quarkusio/quarkus/issues/15492.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Spring Data REST return hibernate-JPA validation ...
I want to get JPA validation and server internal error on JSON format and not stack trace,. Using Spring JPA data rest. MyEntity...
Read more >
Spring Data REST Reference Guide
In general, Spring Data REST does not add functionality to a given data store. This means that, by definition, it should work with...
Read more >
Spring Boot | REST API Request Validation & Exception ...
This tutorial will explain you the process of Handling request validation and exception handling with example#javatechie #SpringBoot ...
Read more >
Top 10 Most Common Spring Framework Mistakes - Toptal
Common Mistake #6: Not Employing Annotation-Based Validation ; class · public · interface ; message() default ; int value() ; class MyAnnotationValidator implements ......
Read more >
Spring Data Rest - validate Bean before save-Springboot
I checked your pom.xml in linked GitHub project. You have just a dependency to validation annotations, but the proper way with Spring Boot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found