Jpa persistence.xml文件与hibernate.conf.xml文件有何不同,在哪种情况下我们应该使用哪个文件

Jpa persistence.xml文件与hibernate.conf.xml文件有何不同,在哪种情况下我们应该使用哪个文件,jpa,Jpa,我正在浏览hibernate示例,在一些示例中使用了persistence.xml,在一些示例中使用了hibernate.cfg.xml。这两个文件之间的区别是什么,这些文件如何影响我们的项目行为,在哪种情况下哪个文件是最好的 我对这两个文件都没有任何问题,我只是想知道,当我们使用这些文件时,项目中是否有任何内部行为变化 在persistence.xml中,我们有 <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan

我正在浏览hibernate示例,在一些示例中使用了persistence.xml,在一些示例中使用了hibernate.cfg.xml。这两个文件之间的区别是什么,这些文件如何影响我们的项目行为,在哪种情况下哪个文件是最好的

我对这两个文件都没有任何问题,我只是想知道,当我们使用这些文件时,项目中是否有任何内部行为变化

在persistence.xml中,我们有

<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="hibernate" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>com.test.jpa.Student</class>
    <properties>
      .....property tags
    </properties>
  </persistence-unit>
</persistence>

org.hibernate.jpa.HibernatePersistenceProvider
com.test.jpa.Student
…属性标签
在hibernate_cfg.xml文件中

<hibernate-configuration>
    <session-factory>
        ......property tags
    </session-factory>
</hibernate-configuration>

……财产标签

当我使用这些文件时,我的两个项目都运行良好,我只想知道与这些文件的区别。

persistence.xml是JPA标准中的配置文件,hibernate.conf.xml是特定于hibernate的文件


建议尽可能使用JPA标准,以独立于底层JPA实现。

感谢您的评论,我对此表示感谢。希望我以后能继续得到积极的回答。我很乐意帮忙。如果我的回答有帮助,请接受它作为正确的答案。谢谢,我想在这里继续讨论,因为我在互联网上读到JPA只是一个蓝图,ORM框架,例如Hibernate正在进行实际的实现。我们能否仅通过不使用任何ORM框架(如Hibernate、iBatis)来创建和运行JPA项目,是吗?不,JPA实现有:Hibernate、EclipseLink、OpenJPA、DataNucleus。IBatis(现在的MyBatis)不是JPA实现.Btw。StackOverflow不是一个讨论平台。我们支持有技术问题的人。你应该在维基百科上开始调查: