【问题标题】:Use Hibernate with Spring Boot, Wildfly and Oracle DB将 Hibernate 与 Spring Boot、Wildfly 和 Oracle DB 结合使用
【发布时间】:2019-01-07 16:26:32
【问题描述】:

我试图了解如何编写一个简单的方法来从数据库中检索数据但没有成功。 我正在使用 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) ...

}

现在我不知道该怎么办。 我创建了一个带有一些 Autowired 变量(如 EntityManagerFactory)的 DAO 类,但它们始终为空。

如何操纵我的实体?

【问题讨论】:

  • 你错过了一些东西,Spring-Boot 避免应用程序服务器(如 WildFly)的兴趣。查看来自spring.io 的示例
  • Spring Boot 可以使用它的嵌入式 AS,但它甚至可以与其他 AS 一起使用。兴趣应该是使配置应用程序更容易。
  • 是的,但是在 AS 服务器中使用 Spring-Boot 完全没用。

标签: oracle hibernate spring-boot wildfly


【解决方案1】:

我在查看this 示例时找到了解决方案。

【讨论】:

    猜你喜欢
    • 2022-11-30
    • 2019-03-03
    • 2020-01-06
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 2016-01-27
    • 2016-03-05
    相关资源
    最近更新 更多