For educational purposes, I want to write an application on Spring + Hibernate with the possibility of authorization and sending messages. I created entities, service and controller, but when I go to the start page on which the list of registered users is selected, the error could not extract ResultSet . I mean that somewhere there is a cant, but because of the lack of experience it is impossible to find it, Google also did not help.

GitHub link
Error log

  • Hibernate says: ERROR: column messages0_.user_id does not exist , apparently in the database, the messages table does not have the user_id field - MrFylypenko
  • This table has an id_user field. - Bleser
  • As a derogation: for such code - session.createQuery("from net.bleser.entity.User as user where user.username='"+username+"'", User.class) - with a ruler. - Roman
  • Where is your attentiveness? user_id and id_user are different fields! Made a pull request for auto-generating tables, you can accept the request. You are missing a little for this project, duplication of bins in xml and annotations, entities have no default constructor, and one gett / set. This is what immediately caught my eye. Here a lot more then pops up. - MrFylypenko
  • I still have little experience in using Spring and Hibernate , I understand that my code is poor. But still, why is the name used for the user_id field user_id since I wrote in the annotation which fields to link @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "id_user"), inverseJoinColumns = @JoinColumn(name = "id_role") - Bleser

1 answer 1

Everything worked when in essence Message did this:

 @ManyToOne(targetEntity = User.class) @JoinColumn(name = "id_user") private User user;