Skip to content
Advertisement

Why is Spring telling me the controller is an unknown entity upon saving a user?

After a few hours of running against the wall with this code, I’ve just about had it. This error is as indescriptive as can be.

My User entity:

https://pastebin.com/fqRJmMCc

JavaScript

TicketController controller with just the function that holds user info:

https://pastebin.com/n7jeciAM

JavaScript

User service and repository essentials:

https://pastebin.com/acYUF7sN

JavaScript

Long story short is that the User object should only need a mail address, password and “enabled” field, which is by default true. Yet, for some reason when this bare minimum of info is passed to the database to make a user, I get an error saying TicketController is an “unknown entity”. Even though TicketController shouldn’t have anything to do with the database:

JavaScript

SignupServiceImpl:

JavaScript

@SpringBootApplication starter:

JavaScript

TicketController has a @Controller annotation, User has an @Entity, SignupServiceImpl has a @Service and still it complains about TicketController not being a known entity…

Config: pom: pastebin.com/B4EeKkmz application config: pastebin.com/KuCndSVY db config class: pastebin.com/FigJScit security config class: pastebin.com/CuAxRErX web config class: pastebin.com/qAHFY3jW

Advertisement

Answer

I think the reason is that you are creating an anonymous class in your code.

JavaScript

needs to be something like

JavaScript

Some Background Information about anonymous classes in Java: https://www.baeldung.com/java-anonymous-classes

A cool tool that might ease the transformation between DTO and Entity in the Controller (I personally use it in some projects and really like it): https://mapstruct.org/

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement