如果可以配置hibernate.cfg.xml(hibernate),我应该如何配置(JPA)persistence.xml文件?

如果可以配置hibernate.cfg.xml(hibernate),我应该如何配置(JPA)persistence.xml文件?,hibernate,Hibernate,这就是我的hibernate.cfg.xml的样子。我的程序正在处理这个问题。我连接到一个MySQL数据库 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hiberna

这就是我的hibernate.cfg.xml的样子。我的程序正在处理这个问题。我连接到一个MySQL数据库

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.default_schema">mintaalkalmazas2</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.show_sql">true</property>
  <mapping resource="Kerdes.hbm.xml"/>
  <mapping resource="TestTable.hbm.xml"/>
 </session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<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="todos" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>Todo</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"></property>
      <property name="javax.persistence.jdbc.user" value="root" />

      <!-- EclipseLink should create the database schema automatically -->
      <property name="eclipselink.ddl-generation" value="create-tables" />
      <property name="eclipselink.ddl-generation.output-mode"
        value="database" />
    </properties>

  </persistence-unit>
</persistence> 

com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306
根
Mintaalkalmaza2
org.hibernate.dialogue.mysqldialogue
真的
这将是persistence.xml。我知道这还不正确。我想连接到同一个MySQL数据库

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.default_schema">mintaalkalmazas2</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.show_sql">true</property>
  <mapping resource="Kerdes.hbm.xml"/>
  <mapping resource="TestTable.hbm.xml"/>
 </session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<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="todos" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>Todo</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"></property>
      <property name="javax.persistence.jdbc.user" value="root" />

      <!-- EclipseLink should create the database schema automatically -->
      <property name="eclipselink.ddl-generation" value="create-tables" />
      <property name="eclipselink.ddl-generation.output-mode"
        value="database" />
    </properties>

  </persistence-unit>
</persistence> 

org.hibernate.jpa.HibernatePersistenceProvider
待办事项
我添加了以下.jar文件:

这一个可以工作:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">

    <persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>

        <properties>

            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="YOUR_PASSWORD"/>

            <!--Hibernate properties-->
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.format_sql" value="false"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

        </properties>
    </persistence-unit>
</persistence>

你想用什么?日食还是冬眠?我想用冬眠。这也许是好的。(我在本地主机上工作,没有任何密码。)我的项目中出现错误,不知道原因。也许我的persistence.xml已经很好了。我得到这个错误:线程“main”javax.persistence.PersistenceException中的异常:在javax.persistence.persistence.createEntityManagerFactory(persistence.java:85)中没有名为todos的EntityManager的持久性提供程序在javax.persistence.persistence.createEntityManagerFactory(persistence.java:54)在main.main(main.java:15)中java中的这一行是原因:factory=Persistence.createEntityManagerFactory(Persistence\u UNIT\u NAME);
PERSISTENCE\u UNIT\u NAME
的值是多少?它是否适合
persistence.xml中的一个?类路径上是否有
Hibernate
JPA
库?私有静态最终字符串持久化\u UNIT\u NAME=“todos”;我认为这应该符合他在persistence.xml中的行:对不起,我想编辑我的问题,我编辑了你的答案。我不想编辑你的答案