I would like to simply print a row from a database created automatically using Spring Boot JPA and Hibernate. I am missing something on how to do it and did not find it online. The reason why I am trying is mostly for testing if the connection to the database is working and also that the function to retrieve data are working.
I am trying to print a row using the main function, but the problem is that @Autowired in the main function does not work as I would like because it's static.
The class where the Forum object is defined.
@Entity
@Table(name = "forum")
public class Forum {
@Id
private long id;
@Column(name = "title")
private String title;
@Column(name = "creationDate")
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
//GETTER AND SETTER
}
//The interface where I define some data retrieval functions.
@Repository
public interface ForumRepository extends CrudRepository<Forum, Long> {
List<Forum> findAll();
Forum findById(long id);
}
@Service
public class Test {
@Autowired
ForumRepository repo;
public Forum test(){
return repo.findById(760);
}
}
JUnit