Boa tarde, estou com o seguinte erro ao tentar enviar a requisição POST para salvar o médico, alguém saberia resolver?
org.hibernate.InstantiationException: Unable to locate constructor for embeddable : med.voll.api.endereco.Endereco
at org.hibernate.metamodel.internal.EmbeddableInstantiatorPojoStandard.instantiate(EmbeddableInstantiatorPojoStandard.java:59) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.type.ComponentType.deepCopy(ComponentType.java:491) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:52) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:278) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:184) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:129) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:53) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:735) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:719) ~[hibernate-core-6.1.5.Final.jar:6.1.5.Final]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
Classe Medico
package med.voll.api.medico;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import med.voll.api.endereco.Endereco;
@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of="id")
@Table(name="medico")
public class Medico {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
private String email;
private String crm;
@Enumerated(EnumType.STRING)
private Especialidade especialidade;
@Embedded
private Endereco endereco;
public Medico (DadosCadastroMedico dados) {
this.nome = dados.nome();
this.email = dados.email();
this.crm = dados.crm();
this.endereco = new Endereco(dados.endereco());
this.especialidade = dados.especialidade();
}
}
Classe Endereço
package med.voll.api.endereco;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Embeddable
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Endereco {
private String logradouro;
private String bairro;
private String cep;
private String numero;
private String complemento;
private String cidade;
private String uf;
public Endereco(DadosEndereco endereco) {
this.logradouro = endereco.logradouro();
this.bairro = endereco.bairro();
this.cep = endereco.cep();
this.numero = endereco.numero();
this.complemento = endereco.complemento();
this.cidade = endereco.cidade();
this.uf = endereco.uf();
}
}