I cannot save my Selectmanycheckbox Primefaces in the database

Asked

Viewed 97 times

0

My View Cad Medico xhtml

   <p:selectCheckboxMenu id="multiple"
                                        value="#{medicoBeanView.objetoSelecionado.especialidades}"
                                        label="Especialidades" multiple="true" filter="true" 
                                        filterMatchMode="startsWith" panelStyle="width:250px" >
                                        <f:selectItems 
                                            value="#{especialidadeBeanView.especialidades}" />
                                    </p:selectCheckboxMenu>

My Converter

 @FacesConverter(forClass = Especialidade.class) 
 public class  EspecialidadeConverter implements Converter, Serializable{

  private static final long serialVersionUID = 1L;

  @Override 
  public Object getAsObject(FacesContext arg0, UIComponent arg1,
  String codigo) { if (codigo != null && !codigo.isEmpty()){ 

  return(Especialidade) 
  HibernateUtil.getCurrentSession().get(Especialidade.class,              
  new Long(codigo)); 
} return codigo; }

  @Override 
  public String getAsString(FacesContext arg0, UIComponent arg1,
  Object objeto) { 
   if (objeto != null){ 
       Especialidade c = (Especialidade)  objeto; 
       return c.getIdEspecialidade() != null && c.getIdEspecialidade() > 0 ?
       c.getIdEspecialidade().toString() : null; } 
       return null; 
   }

  }

Medico Model Mapping

  /**
 * @author Humberto
 *
 */
@Audited
@Entity
@Table(name = "medico")
@SequenceGenerator(name = "medico_seq", sequenceName = "medico_seq", initialValue = 1, allocationSize = 1)
public class Medico  implements Serializable {

    private static final long serialVersionUID = 1L;

    @IdentificaCampoPesquisa(descricaoCampo = "Médico", campoConsulta = "pessoa.pessoaNome", principal = 2)
    @JoinColumn(unique=true , referencedColumnName="idPessoa")
    @OneToOne(cascade = CascadeType.ALL)
    private Pessoa pessoa = new Pessoa();

    @IdentificaCampoPesquisa(descricaoCampo = "Código", campoConsulta ="idMedico", principal = 1 )
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "medico_seq")
    private Long idMedico;

    private String numeroCrm;

    //private String[] selecionaEspecialidades;

    /*
     * private List<String> listaEspecialidades;
     * 
     * @PostConstruct public void getEspecialidades() { listaEspecialidades = new
     * ArrayList<String>(); listaEspecialidades.add("Otorrino");
     * listaEspecialidades.add("Pediatra");
     * listaEspecialidades.add("Cirurgião Vascular");
     * listaEspecialidades.add("Cardiologista");
     * listaEspecialidades.add("Oftalmologista");
     * listaEspecialidades.add("Endocrino"); listaEspecialidades.add("Urologista");
     * listaEspecialidades.add("Cirurgião de Membros Superiores"); }
     * 
     */
    @Temporal(TemporalType.DATE)
    private Date dataInscricaoCrm;

    @Version
    @Column(name = "versionNum")
    private int versionNum;

    @ManyToMany
    @JoinTable(name="medico_especialidade",
    joinColumns={
            @JoinColumn(name="medicoId", referencedColumnName="idMedico")},
    inverseJoinColumns={
            @JoinColumn(name="especialidadeId", referencedColumnName="idEspecialidade")}) 
    private List<Especialidade>  especialidades = new ArrayList<>();


    //GETTERS E SETTERS-------------------------
    public Long getIdMedico() {
        return idMedico;
    }

    public void setIdMedico(Long idMedico) {
        this.idMedico = idMedico;
    }

    public Date getDataInscricaoCrm() {
        return dataInscricaoCrm;
    }

    public void setDataInscricaoCrm(Date dataInscricaoCrm) {
        this.dataInscricaoCrm = dataInscricaoCrm;
    }

    public int getVersionNum() {
        return versionNum;
    }

    public void setVersionNum(int versionNum) {
        this.versionNum = versionNum;
    }

    public Pessoa getPessoa() { 
        return pessoa; 
    }

    public void setPessoa(Pessoa pessoa) { 
         this.pessoa = pessoa; 
    }

    public String getNumeroCrm() {
        return numeroCrm;
    }

    public void setNumeroCrm(String numeroCrm) {
        this.numeroCrm = numeroCrm;
    }

    public String[] getSelecionaEspecialidades() {
        return selecionaEspecialidades;
    }

    public void setSelecionaEspecialidades(String[] selecionaEspecialidades) {
        this.selecionaEspecialidades = selecionaEspecialidades;
    }



    // HASH CODE & EQUALS





    public List<Especialidade> getEspecialidades() {
        return especialidades;
    }

    public void setEspecialidades(List<Especialidade> especialidades) {
        this.especialidades = especialidades;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((idMedico == null) ? 0 : idMedico.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Medico other = (Medico) obj;
        if (idMedico == null) {
            if (other.idMedico != null)
                return false;
        } else if (!idMedico.equals(other.idMedico))
            return false;
        return true;
    }

}

Especialidade Model Mapping

/**
 * @author Humberto
 *
 */
@Entity
@Audited
@Table(name="especialidade")
@SequenceGenerator(name="especialidade_seq", sequenceName="especialidade_seq", initialValue = 1, allocationSize = 1)
public class Especialidade implements Serializable {

    private static final long serialVersionUID = 1L;

    @IdentificaCampoPesquisa(descricaoCampo = "Código", campoConsulta ="idEspecialidade", principal = 1 )
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "especialidade_seq")
    private Long idEspecialidade;

    @IdentificaCampoPesquisa(descricaoCampo = "Especialidade", campoConsulta = "nomeEspecialidade", principal = 2)
    private String nomeEspecialidade;

    private String observacao;

    @Version
    @Column(name = "versionNum")
    private int versionNum;

    @ManyToMany(mappedBy="especialidades")
    private List<Medico>  medicos = new ArrayList<>();

    //EQUALS E HASCODE ----------------------------------------

    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((idEspecialidade == null) ? 0 : idEspecialidade.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Especialidade other = (Especialidade) obj;
        if (idEspecialidade == null) {
            if (other.idEspecialidade != null)
                return false;
        } else if (!idEspecialidade.equals(other.idEspecialidade))
            return false;
        return true;
    }

    //GETTERS E SETTERS----------------------------------------------

    public Long getIdEspecialidade() {
        return idEspecialidade;
    }
    public void setIdEspecialidade(Long idEspecialidade) {
        this.idEspecialidade = idEspecialidade;
    }
    public String getNomeEspecialidade() {
        return nomeEspecialidade;
    }
    public void setNomeEspecialidade(String nomeEspecialidade) {
        this.nomeEspecialidade = nomeEspecialidade;
    }
    public String getObservacao() {
        return observacao;
    }
    public void setObservacao(String observacao) {
        this.observacao = observacao;
    }
    public int getVersionNum() {
        return versionNum;
    }
    public void setVersionNum(int versionNum) {
        this.versionNum = versionNum;
    }
    public List<Medico> getMedicos() {
        return medicos;
    }
    public void setMedicos(List<Medico> medicos) {
        this.medicos = medicos;
    }




}   

Specialityecontroller

public List<SelectItem> getListEspecialidades() throws Exception {
        List<SelectItem> list = new ArrayList<SelectItem>();

        List<Especialidade> especialidades = super.findListByQueryDinamica(" from Especialidade");

        for (Especialidade especialidade : especialidades) {
            list.add(new SelectItem(especialidade,especialidade.getNomeEspecialidade()));
        }
        return list;
    }

Especialidadebeanview

public List<SelectItem> getEspecialidades() throws Exception {
    return especialidadeController.getListEspecialidades();
}

Botao Salvar

public void saveNotReturn() throws Exception {
        list.clean();
        objetoSelecionado = medicoController.merge(objetoSelecionado);
        list.add(objetoSelecionado);
        objetoSelecionado = new Medico();
        sucesso();
    }

Stack Error When Clicking Save Button

javax.el.ELException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
    at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
    at 
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field br.com.projeto.model.classes.Especialidade.idEspecialidade to java.lang.String

3 answers

0

Good afternoon friend , thank you for your attention.

I made the change in Select Item and the error remains.

ADVERTÊNCIA: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
javax.el.ELException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
    at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.paradise.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:32)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at br.com.projeto.filter.FilterOpenSessionInView.doFilter(FilterOpenSessionInView.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:227)
    at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3875)
    at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3583)
    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
    at org.hibernate.type.EntityType.replace(EntityType.java:283)
    at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:508)
    at org.hibernate.type.CollectionType.replace(CollectionType.java:575)
    at org.hibernate.type.AbstractType.replace(AbstractType.java:176)
    at org.hibernate.type.TypeHelper.replaceAssociations(TypeHelper.java:262)
    at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:589)
    at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:389)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:345)
    at com.sun.proxy.$Proxy49.merge(Unknown Source)
    at br.com.framework.implementacao.crud.ImplementacaoCrud.merge(ImplementacaoCrud.java:87)
    at br.com.projeto.bean.view.MedicoBeanView.saveNotReturn(MedicoBeanView.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    ... 72 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field br.com.projeto.model.classes.Especialidade.idEspecialidade to java.lang.String
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
    at java.lang.reflect.Field.get(Field.java:379)
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)
    ... 102 more

javax.faces.FacesException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.paradise.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:32)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at br.com.projeto.filter.FilterOpenSessionInView.doFilter(FilterOpenSessionInView.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
    at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    ... 64 more
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.projeto.model.classes.Especialidade.idEspecialidade
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:227)
    at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3875)
    at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3583)
    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
    at org.hibernate.type.EntityType.replace(EntityType.java:283)
    at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:508)
    at org.hibernate.type.CollectionType.replace(CollectionType.java:575)
    at org.hibernate.type.AbstractType.replace(AbstractType.java:176)
    at org.hibernate.type.TypeHelper.replaceAssociations(TypeHelper.java:262)
    at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:589)
    at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:389)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:345)
    at com.sun.proxy.$Proxy49.merge(Unknown Source)
    at br.com.framework.implementacao.crud.ImplementacaoCrud.merge(ImplementacaoCrud.java:87)
    at br.com.projeto.bean.view.MedicoBeanView.saveNotReturn(MedicoBeanView.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    ... 72 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field br.com.projeto.model.classes.Especialidade.idEspecialidade to java.lang.String
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
    at java.lang.reflect.Field.get(Field.java:379)
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)
    ... 102 more
  • Okay, that’s where you need to take it slow, but the mistake is what I said there, data typing, you’re trying to put a string where it’s a long.

0


Solved with converting this way !

@FacesConverter( value="especialidadeConverter",forClass = Especialidade.class)
public class EspecialidadeConverter implements Converter, Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {

    if (value != null) {
            //Long codigo = new Long(value); 
            try {
                return new EspecialidadeController().findByPorId(Especialidade.class, Integer.valueOf(value).longValue());
            } catch (Exception e) {
                return new Especialidade();
            }
        }
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
         try {
                return String.valueOf(((Especialidade) value).getIdEspecialidade());
            } catch (Exception e) {
                return "";
            }
        }


    }

0

Humberto, you are trying to insert a String into a Long type object.

Caused by: java.lang.Illegalargumentexception: Can not set java.lang.Long field br.com.projeto.model.classes.Especialidade.idEspecialidade to java.lang.String

Adjust the reference of your Selectitem.

Change of:

list.add(new SelectItem(especialidade,especialidade.getNomeEspecialidade()));

To:

list.add(new SelectItem(especialidade.getIdEspecialidade(),especialidade.getNomeEspecialidade()));

I hope I’ve helped.

Browser other questions tagged

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