Answer the question
In order to leave comments, you need to log in
Why can't I initialize the repository?
when I try to initialize the repository, I get an error
controller code MainController:
@Controller
public class MainController {
public final FlagRepository flagRepository;
@Autowired
public MainController(FlagRepository flagRepository) {
this.flagRepository = flagRepository;
}
@GetMapping("/")
public String changeFlag(){
// Flag flag = flagRepository.findById(1L);
// flag.setFlag(0);
// flagRepository.save(flag.getId());
return "main";
}
// ...
}
import com.blrmyfc.ComputerVision.domain.Flag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface FlagRepository extends JpaRepository<Long, Flag> {
Flag findById(Long l);
}
import javax.persistence.*;
@Entity
@Table(name = "flag")
public class Flag {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private int flag;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public Flag() {
}
public Flag(int flag) {
this.flag = flag;
}
}
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController' defined in file [/home/blurmayface/Документы/ComputerVision/target/classes/com/blrmyfc/ComputerVision/controller/MainController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flagRepository' defined in com.blrmyfc.ComputerVision.repo.FlagRepository defined in @EnableJpaRepositories declared on ComputerVisionApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Long
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flagRepository' defined in com.blrmyfc.ComputerVision.repo.FlagRepository defined in @EnableJpaRepositories declared on ComputerVisionApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Long
java.lang.IllegalArgumentException: Not a managed type: class java.lang.Long
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:582) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:85) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
Answer the question
In order to leave comments, you need to log in
In the repository, first entity then Long, you have the opposite
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question