【问题标题】:How does JPA find the concrete implementation to call?JPA 如何找到要调用的具体实现?
【发布时间】:2020-08-22 08:44:39
【问题描述】:

我正在做一个项目,我必须抽象出接口并将其与具体实现分开。例如,JPA 只是接口,在底层,它调用具体实现之一,例如 Hibernate 库。所以我的问题是它如何知道要调用哪个实现。到目前为止,从我的研究中,我了解到只需将 Hibernate 添加为依赖项,无需担心拼凑。它在后台是如何工作的?

【问题讨论】:

  • 你使用的是 Spring,如果是,你使用的是 Spring boot 吗?

标签: java jpa interface


【解决方案1】:

您必须在 peristence.xml 中定义持久性提供程序以指定您使用的实现。

这个使用Hibernate作为实现。

<persistence-unit name="sampleEmf" transaction-type="JTA">

    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    ...

</persistence-unit>

这个使用 EclipseLink 作为实现。

<persistence-unit name="sampleEmf" transaction-type="JTA">

    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    ...

</persistence-unit>

【讨论】:

    猜你喜欢
    • 2019-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    相关资源
    最近更新 更多