So, I'm trying to implement a database into a kafka listener, but when i start it, it crashed and i can't figure out why.
here's the code
Model
package br.com.ottimizza.ListenerServico.domain.model;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import org.springframework.data.annotation.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.Data;
@Data
@Entity
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "ot_log_questor_post_baixa")
public class LogQuestor {
@Id
@Column
@GeneratedValue(strategy = GenerationType.AUTO)
private BigInteger id;
@Column
Date ot_created_at;
@Column
Body ot_objeto_questor;
@Column
String ot_objeto_texto_questor;
@Column
String ot_status_req;
@Column
String ot_token_usuario;
}
Body Object
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Body implements Serializable {
private static final long serialVersionUID = 1L;
String fileLink;
String zenTokenUsuario;
String domain;
String filename;
String cnpj;
HashMap<String, String> propriedades;
}
Repository
package br.com.ottimizza.ListenerServico.repository;
import java.math.BigInteger;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import br.com.ottimizza.ListenerServico.domain.model.LogQuestor;
@Repository
public interface LogQuestorRepository extends JpaRepository<LogQuestor, BigInteger> {
public Optional<LogQuestor> findById(BigInteger id);
}
the method to save it
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Autowired
LogQuestorRepository repository;
public void saveToDB(String message, String status, String token) {
LogQuestor reqToSv = new LogQuestor();
//assignment of carachteristics
repository.save(reqToSv);
}
Note: the code has some things that were ommited but nothing that's wrong or relevant, I'm sure
The error i'm getting
2022-10-21T20:32:34.903633 00:00 app[web.1]: 2022-10-21 20:32:34.903 WARN 4 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logQuestorRepository' defined in br.com.ottimizza.ListenerServico.repository.LogQuestorRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: br.com.ottimizza.ListenerServico.domain.model.LogQuestor
2022-10-21T20:32:34.904798 00:00 app[web.1]: 2022-10-21 20:32:34.904 WARN 4 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'services': Unsatisfied dependency expressed through field 'tareffa'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.ottimizza.ListenerServico.client.ClientTareffa': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logQuestorRepository' defined in br.com.ottimizza.ListenerServico.repository.LogQuestorRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: br.com.ottimizza.ListenerServico.domain.model.LogQuestor
2022-10-21T20:32:34.905820 00:00 app[web.1]: 2022-10-21 20:32:34.904 INFO 4 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
CodePudding user response:
It was the wrong @Id
annotation class import.
I was importing the
import org.springframework.data.annotation.Id;
and the correct was
import javax.persistence.Id;
Thanks a lot @JimGarrison