Conversion error when sending input to controller to save

Asked

Viewed 48 times

2

Good evening guys, I’m having trouble solving this problem, I hope you can help me... When trying to save data from View only one field returns this error:

Failed to Convert Property value of type java.lang.String to required type com.sisdcon.oficinas.model.Usuarios for Property corretor_heados; nested Exception is java.lang.Illegalstateexception: Cannot Convert value of type java.lang.String to required type com.sisdcon.oficinas.model.Usuarios for Property corretor_heados: no matching Editors or Conversion Strategy found

on the screen has 3 more fields of the same type and works correctly, below I leave the Model, Controller (save method) and the view snippet (containing the fields)

Model....

 @Table(name = "heados")
@Entity
public class Atendimentos {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id_heados;

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "cadastro_heados", referencedColumnName = "id_cadastros", updatable = false, insertable = false)
   @NotNull(message = "Cliente Obrigatório.")
   private Cadastros cadastro_heados;

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "veiculo_heados", referencedColumnName = "id_veiculos", updatable = false, insertable = false)
   @NotNull(message = "Veículo Obrigatório.")
   private Veiculos veiculo_heados;

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "seguradora_heados", referencedColumnName = "id_cadastros", updatable = false, insertable = false)
   private Cadastros seguradora_heados;

   ?//--- ESTE É O CAMPO QUE OCORRE O ERRO!!!
   @ManyToOne( fetch = FetchType.EAGER)
   @JoinColumn(name = "corretor_heados", referencedColumnName = "id_usuarios", updatable = false, insertable = false)
   private Usuarios corretor_heados;


   private Long usuario_heados;
   private String veiculo_km_heados;

Controller... saving method

@RequestMapping(method = RequestMethod.POST)
   public String salvar(@Validated Atendimentos atendimentos, Errors errors, RedirectAttributes attributes) {

      System.out.println("vou tentar salvar");

      ///-- O SISTEMA ENTRA AQUI RETORNANDO O ERRO
      if (errors.hasErrors()) { 
         System.out.println("parei no erro!");
         return CADASTROVIEW;
      }
      try {

         atendimentosService.salvar(atendimentos);

      } catch (IllegalArgumentException e) {
         return CADASTROVIEW;
      }

      return "redirect:/atendimentos/"+atendimentos.getId_heados();
   }

View section contento os campo

<form id="FormAtendimentos" method="POST" th:action="@{/atendimentos}" th:object="${atendimentos}">

   <input type="text" th:field="*{seguradora_heados}">

   <input type="text" th:field="*{veiculo_heados}">

    <!--  ESSE É O CAMPO QUE O SISTEMA RETORNA O ERRO    -->
   <input type="text" th:field="*{corretor_heados}"> 


</form>

I realized that, only when filling in the case of Editing, it does not fill with the table ID "a number" it fills with the reference to the model in this way...

com.sisdcon.oficinas.model.Usuarios@22120bd8

another thing is in the query that JPA assembles, in it I have several joins, hence it even time uses Ner Join or left Uter Join.... below I leave the query mounted by JPA....

select
    atendiment0_.id_heados as id_heado1_5_0_,
    atendiment0_.cadastro_heados as cadastr25_5_0_,
    atendiment0_.corretor_heados as correto26_5_0_,
    atendiment0_.custosadicionais_heados as custosad2_5_0_,
    atendiment0_.dataentrada_heados as dataentr3_5_0_,
    atendiment0_.dataprevsaida_heados as dataprev4_5_0_,
    atendiment0_.datasaida_heados as datasaid5_5_0_,
    atendiment0_.deducao_heados as deducao_6_5_0_,
    atendiment0_.extramaoobra_heados as extramao7_5_0_,
    atendiment0_.extrapeca_heados as extrapec8_5_0_,
    atendiment0_.franquia_heados as franquia9_5_0_,
    atendiment0_.maoobra_heados as maoobra10_5_0_,
    atendiment0_.materialpintura_heados as materia11_5_0_,
    atendiment0_.obschecklist_heados as obschec12_5_0_,
    atendiment0_.obsextras_heados as obsextr13_5_0_,
    atendiment0_.seguradora_heados as segurad27_5_0_,
    atendiment0_.sinistronumero_heados as sinistr14_5_0_,
    atendiment0_.tipoatendimento_heados as tipoate15_5_0_,
    atendiment0_.usuario_heados as usuario16_5_0_,
    atendiment0_.veiculo_heados as veiculo28_5_0_,
    atendiment0_.veiculo_km_heados as veiculo17_5_0_,
    cadastros1_.id_cadastros as id_cadas6_0_1_,
    cadastros1_.bairro_cadastros as bairro_c7_0_1_,
    cadastros1_.cep_cadastros as cep_cada8_0_1_,
    cadastros1_.cidade_cadastros as cidade_c9_0_1_,
    cadastros1_.cpfcnpj_cadastros as cpfcnpj_2_0_1_,
    cadastros1_.dtnasc_cadastros as dtnasc_10_0_1_,
    cadastros1_.endereco_cadastros as enderec11_0_1_,
    cadastros1_.ie_cadastros as ie_cada12_0_1_,
    cadastros1_.nome_cadastros as nome_ca13_0_1_,
    cadastros1_.numero_cadastros as numero_14_0_1_,
    cadastros1_.razaosocial_cadastros as razaoso15_0_1_,
    cadastros1_.tipo_cadastros as tipo_cad5_0_1_,
    cadastros1_.uf_cadastros as uf_cada16_0_1_,
    usuarios2_.id_usuarios as id_usuar3_11_2_,
    usuarios2_.grupo_usuarios as grupo_us4_11_2_,
    usuarios2_.nome_usuarios as nome_usu5_11_2_,
    cadastros3_.id_cadastros as id_cadas6_0_3_,
    cadastros3_.bairro_cadastros as bairro_c7_0_3_,
    cadastros3_.cep_cadastros as cep_cada8_0_3_,
    cadastros3_.cidade_cadastros as cidade_c9_0_3_,
    cadastros3_.cpfcnpj_cadastros as cpfcnpj_2_0_3_,
    cadastros3_.dtnasc_cadastros as dtnasc_10_0_3_,
    cadastros3_.endereco_cadastros as enderec11_0_3_,
    cadastros3_.ie_cadastros as ie_cada12_0_3_,
    cadastros3_.nome_cadastros as nome_ca13_0_3_,
    cadastros3_.numero_cadastros as numero_14_0_3_,
    cadastros3_.razaosocial_cadastros as razaoso15_0_3_,
    cadastros3_.tipo_cadastros as tipo_cad5_0_3_,
    cadastros3_.uf_cadastros as uf_cada16_0_3_,
    veiculos4_.id_veiculos as id_veicu1_12_4_,
    veiculos4_.ano_veiculos as ano_veic2_12_4_,
    veiculos4_.cor_veiculos as cor_veic3_12_4_,
    veiculos4_.modelo_veiculos as modelo_v4_12_4_,
    veiculos4_.motor_veiculos as motor_ve5_12_4_,
    veiculos4_.placa_veiculos as placa_ve6_12_4_,
    veiculosmo5_.id_veiculosmodelos as id_veicu3_14_5_,
    veiculosmo5_.marca_veiculosmodelos as marca_ve5_14_5_,
    veiculosmo5_.nome_veiculosmodelos as nome_vei4_14_5_ 
from
    heados atendiment0_ 
inner join
    cadastros cadastros1_ 
        on atendiment0_.cadastro_heados=cadastros1_.id_cadastros 
left outer join
    usuarios usuarios2_ 
        on atendiment0_.corretor_heados=usuarios2_.id_usuarios 
left outer join
    cadastros cadastros3_ 
        on atendiment0_.seguradora_heados=cadastros3_.id_cadastros 
inner join
    veiculos veiculos4_ 
        on atendiment0_.veiculo_heados=veiculos4_.id_veiculos 
left outer join
    veiculosmodelos veiculosmo5_ 
        on veiculos4_.modelo_veiculos=veiculosmo5_.id_veiculosmodelos 
where
    atendiment0_.id_heados=?

If you need any more information please ask,

Thank you in advance!!!

Blinded!

Renato Muniz.

  • No suggestions guys!?

1 answer

0

I was able to solve only now, and what happened is that it is mandatory have a Repository even if empty, I only created when I wanted to do a manual search, ie, create a custom query, after I created Repository even if empty, funfou!!! When you go through the same trouble, try this!! Thanks!!!

Browser other questions tagged

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