Spring Boot – Common errors and fixes.

  1. In a Spring Boot app, after logging in into ADFS authentication, clicking on a button/link with a post request will take you again to ADFS authentication screen with the below error:

org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL contained a potentially malicious String “;”

Fix:

Add the below property to application.yml. It worked.

server:
  servlet
    session:
      tracking-modes: cookie

  1. Error: Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM com.jsession4d.reactivedemo.User WHERE id = :id]
public interface UserRepository extends JpaRepository<User, Long> {
    @Query(value = "SELECT * FROM User WHERE id = :id")
    User findUser(Long id);
}

The above code will throw the below error as SELECT * is not a valid syntax for JPQL.

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM com.jsession4d.reactivedemo.User WHERE id = :id]

Fix:

  1. Either we can use the below JPQL syntax (or)
@Query(value = "SELECT u FROM User u WHERE id = :id")
User findUser(Long id);
  1. We can mark the query as a native query.
@Query(value = "SELECT * FROM User WHERE id = :id", nativeQuery = true)
User findUser(Long id);

%d bloggers like this: