[我在导入JPA批注并仅使用单个hibernate属性时使用JPA或Hibernate吗?

问题描述 投票:0回答:2

我可以在stackoverflow中看到类似的问题,但他引用的示例完全不同,并且给出了与之相关的答案。

在我们的项目中,我有JPA批注

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

在Persistance.xml中,我也具有休眠属性:

<persistence-unit name="IntegratorMasterdataDS" transaction-type="JTA" >
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
<!--            <jta-data-source>java:/datasources/Ifs9ErgointDS1</jta-data-source>  -->
                <jta-data-source>java:/datasources/IfsDS</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.show_sql" value="false" />
         <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>
    </persistence-unit>

   @PersistenceContext(unitName = "IntegratorMasterdataDS")
   protected EntityManager em;
   em.persist
   em.save
   em.flush
   em.find
   em.merge

我在使用Hibernate作为JPA实现的Wildfly中进行部署。

被问到您是在使用JPA还是Hibernate时我应该回答什么?

根据当前的理解,如果我们在代码或persistance.xml中使用单个Hibernate属性,那么可以说我们正在使用Hibernate,因为它使项目依赖于Hibernate。这种理解很好吗?

如果没有,那么我应该在项目中添加更多内容以表明我正在使用休眠模式?

java hibernate jpa spring-data-jpa hibernate-mapping
2个回答
1
投票

Java Persistence API(JPA)是Java规范,用于访问,持久化和管理Java对象/类与关系数据库之间的数据

然而,休眠是JPA的具体实现。

作为类比,请考虑将JPA作为接口,并将休眠作为其具体实现之一。因此,可以说您正在使用JPA的休眠实现。

签出this link以查看JPA的其他实现。


0
投票

被问到您是使用JPA还是Hibernate时,我应该回复?

我正在将JPA与Hibernate一起实现。

根据目前的理解,如果我们使用单个Hibernate属性,在代码或persistance.xml中,那么我们可以说我们正在使用Hibernate因为它使项目休眠依赖。这种理解很好吗?

我会说:不。您正在使用标准的JPA批注。 persistence.xml中提供的属性是可选的。您不需要它们来使您的应用程序正常运行。例如,您不需要show_sqlhbm2ddl.auto可以替换为标准的JPA属性:https://docs.oracle.com/javaee/7/tutorial/persistence-intro005.htm

© www.soinside.com 2019 - 2024. All rights reserved.