Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Java Spring Boot application adds the suffix '_seq' to table users

On execution of my spring boot application with MySQL as data source, it fails with below error message

Table 'schema.users_seq' doesn't exist

I have an @Entity class Users with an AUTO_INC field Id

@Entity
    @Table(appliesTo = "users")
    public class Users {
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="uid")
    private long id;
    }

Below is my User controller class


    @RestController
    @RequestMapping("/cm/api/user")
    public class UserController {
    @Autowired
    UsersRepository usersRepository;
    @GetMapping("/{username}")
    public void getUser(@PathVariable("username") String userName) {
    }
    @PostMapping("/add")
    public void addNewUser(@RequestBody Users users) {
    usersRepository.save(users);
    }
   }

There are some other articles on the same issue, but it all ended with the question if the class has AUTO_INC field.

like image 410
Eshwar Avatar asked Oct 30 '25 12:10

Eshwar


1 Answers

Your app tries to generate a long ID for your Users entity by retrieving a value from the users_seq. You need to change the @GeneratedValue(strategy = GenerationType.AUTO) according to your DDL structure. As you didn't include that in your post, I can only assume how you mapped it, so I can only recommend that you read this article by Hibernate maintainer Vlad Mihalcea about why you should not use the AUTO JPA GenerationType with MySQL and Hibernate.

like image 177
Times Avatar answered Nov 02 '25 02:11

Times



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!