Strange exception: "The name must not be empty or empty!"

I am experiencing a strange error in a Spring project that looks like this:

SEVERE: Servlet.service () for the servlet [calzoneServlet] in the context of the path [/ calzone] threw an exception [Request processing failed; The nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: the name must not be empty or empty !; The nested exception is java.lang.IllegalArgumentException: the name must not be empty or empty!] With the root cause java.lang.IllegalArgumentException: the name must not be empty or empty!

In this project, all models are mapped to the database using hibernate and jpa. The interface uses Twitter Bootstrap (with Spring form validation, etc.)

The error occurs in different parts of the program, one of which is a controller for activating a user account (code below). For me, this seems like some kind of validation error, but it is not the error I have ever identified. Since I cannot pinpoint the exact location of the error, I only provide the controller below. It should be noted that any debugging messages (whether through the logger or just the old sysout) are activateUsernot displayed in the method .

All dependencies (pom.xml) can be found here: http://pastebin.com/fs7SG0W2 Web.xml here: http://pastebin.com/vAJh29Aw Here you can find the full stack: http://codepad.org/p0Yt5hi2 ( on the code as it has horizontal scrolling)

- , , - , , ?

@Controller
public class ActivateAccountController {
    final Logger logger = LoggerFactory.getLogger(getClass());
    @RequestMapping(value = "/activate/{keyString}", method = RequestMethod.GET)
    public String activateUser(@PathVariable String keyString) {
        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        KeyService keyService = (KeyService) context.getBean("keyService");
        UserService userService = (UserService) context.getBean("userService");
        User user;
        try {
            logger.error("DID I GET HERE?");
            user = keyService.findUserByKey(keyString);
        } catch (KeyNotFoundException ex) {
            return "ActivatedNotAccount";
        } finally {
            // Close the application context in every case
            context.close();
        }
        // Activate the in-memory user
        userService.activateUser(user);
        // Delete the key from the database
        keyService.deleteKey(keyString);
        // Finally, update the user in the database
        userService.updateUser(user);
        logger.info("Acticated user with ID \"{}\", First name: \"{}\", Last name: \"{}\" and username: \"{}\"",
                user.getId(), user.getPerson().getFirstName(), user.getPerson().getLastName(), user.getUsername());
        return "ActivatedAccount";
    }
}
+4
3

KeyService Spring JPA method findKeyByKeyString(). Spring Data JPA, , - .

org.springframework.data.jpa.repository.query.StringQuery.getBindingFor(StringQuery.java:104), if !StringUtils.hasText(name), , , findKeyByKeyString().

+10

: , @Param. , @QueryParam.

, @Param, .

:

, , : JpaRepository ,

@Query(value = "SELECT * FROM table WHERE property=:something", nativeQuery = true).

, . , :

@Query(value = "SELECT * FROM table WHERE property=(?1)", nativeQuery = true).

( , ).

+9

, @Param ( "appname" ) args:

@Query ( "SELECT p.preferenceId.userId FROM Preference p WHERE p.preferenceId.appName =: appname" )   getAppUsers ( @Param ( "appname" ) String appname);

+5
source

Source: https://habr.com/ru/post/1534155/


All Articles