将 Hibernate 与 Spring Boot、Wildfly 和 Oracle DB 一起使用

Use Hibernate with Spring Boot, Wildfly and Oracle DB

我试图了解如何编写一个简单的方法来从数据库中检索数据但没有成功。 我正在使用 Spring Boot 2.1、Hibernate(由 Spring Boot 提供)、Wildfly 14 和 Oracle 12。

与数据库的连接似乎可以使用 standalone.xml 上的数据源(由 application.properties 文件读取)。我的问题是,如果我尝试使用 EntityManager、EntityManagerFactory 或 Repositories,它们总是为空,我不明白为什么。

可能我在配置上遗漏了一些东西。我的 application.properties 是:

# Datasource
spring.datasource.jndi-name=java:/TestDB

# Hibernate
hibernate.dialect: org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql: true

# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.hibernate.SQL=debug

我像这样定义了一个简单的实体

public class MyEntity {

@Id
@Column
private int myId;
private int anotherData;

... (getters and setters) ...

}

现在我不知道该怎么办。 我用一些自动装配的变量(比如 EntityManagerFactory)创建了一个 DAO class,但它们总是空的。

如何操作我的实体?

我通过查看 this 示例找到了解决方案。