Problems with Spring Boot Insert

Asked

Viewed 255 times

1

I am trying to insert a user into the Postgresql database on the Heroku web server.

The attributes of the user in the Postgresql database

inserir a descrição da imagem aqui

As you can see, there’s a column called groups, and every time I’m trying to submit the envelope it saves all the data from the other columns except the groups, I did everything right in the implementation and do not know what is wrong.

Soon after submitting the form when I check by performing a select in the table is null, but I put a print in the controller to know if it is actually sending the data as in the code below;

System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>" + usuario.getGrupos());

What happens is that this component in the HTML page is actually submitted as shown in the log below;

2017-07-03T19:10:33.983122+00:00 heroku[router]: at=info method=POST path="/usuarios/novo" host=wb-arm-wladimir.herokuapp.com request_id=85833251-bd54-44a5-ae4e-fb78
fecd9da0 fwd="177.223.27.17" dyno=web.1 connect=0ms service=344ms status=302 bytes=427 protocol=https
2017-07-03T19:10:33.845939+00:00 app[web.1]: <<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>[br.com.arm.model.Grupo@20]
2017-07-03T19:10:34.140090+00:00 heroku[router]: at=info method=GET path="/usuarios/novo" host=wb-arm-wladimir.herokuapp.com request_id=8131592c-831e-4d30-9e90-b16a8
6fba6a2 fwd="177.223.27.17" dyno=web.1 connect=1ms service=42ms status=200 bytes=8974 protocol=https
2017-07-03T19:10:34.358827+00:00 heroku[router]: at=info method=GET path="/javascripts/vendors/jquery.maskMoney.min.js" host=wb-arm-wladimir.herokuapp.com request_id
=75c6c474-e484-4ee4-8dad-2be026665f70 fwd="177.223.27.17" dyno=web.1 connect=1ms service=15ms status=200 bytes=5510 protocol=https

This is my controller page

https://github.com/wladyband/arm/blob/master/arm/src/main/java/br/com/arm/controller/UsuarioController.java

This is my user entity

https://github.com/wladyband/arm/blob/master/arm/src/main/java/br/com/arm/model/Usuario.java

This is my web page

https://github.com/wladyband/arm/tree/master/arm/src/main/resources/templates/usuario

Can anyone see anything wrong with my Spring Boot project.

If I go to inspect the page I can find it below;

inserir a descrição da imagem aqui

It’s weird 'cause it feels like everything’s right!

if I put this line of code in the controller

System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>" + usuario.getGrupos().size());

And mark the administrator group the result will be 1, That means you’re right.

then it’s all very strange.

The strange thing is that when submitting the user form it does not insert the data in the groups column, but it inserted the data in the user table;

inserir a descrição da imagem aqui

This could only happen if the groups column in the user table were saved, but it does not save the data in the groups column, but the usual group_groups table are saved.

1 answer

1


Good evening as far as I know relationship Manytomany creates a third table with key in case of user and group. So there’s nothing wrong with what you’ve shown. When retrieving this entity it brings the filled list of groups?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.