Hibernate 冬眠+;Mysql没有数据库填充

Hibernate 冬眠+;Mysql没有数据库填充,hibernate,Hibernate,我在尝试一个简单的教程 我已经按照上面写的所有步骤进行了操作,但仍然不起作用。 这就是我得到的: 这是我的主要观点: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package hibernatetest; import org.hibernate.Session; import org.hibernate.SessionFacto

我在尝试一个简单的教程

我已经按照上面写的所有步骤进行了操作,但仍然不起作用。 这就是我得到的:

这是我的主要观点:

   /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernatetest;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

/**
 *
 * @author ktelfon
 */
public class HibernateTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Session session = null;
        try {
            SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure("hibernatetest/hibernate.cfg.xml").buildSessionFactory();
            session = sessionFactory.openSession();
            session.beginTransaction();

            System.out.println("Populating the database !");
            Customer customer = new Customer();
            customer.setCustomerName("Chathura");
            customer.setCustomerAddress("221B,Moratuwa");
            customer.setCustomerEmail("priyankarahac@gmail.com");

            session.save(customer);
            session.getTransaction().commit();

            System.out.println("Done!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            session.flush();
            session.close();
        }
    }
}
这是我的cfg:

<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/retailer?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">root</property>
    <property name="show_sql">true</property>
    <mapping resource="hibernatetest/customersmapping.hbm.xml"/>
    <mapping/>
  </session-factory>
</hibernate-configuration>

org.hibernate.dialogue.mysqldialogue
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/retailer?zeroDateTimeBehavior=convertToNull
根
根
真的
和我的映射:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="hibernatetest.Customer" table="customers">
  <id column="C_ID" name="customerID" type="int">
  <generator class="native">
  </generator></id>
  <property name="customerName">
  <column name="name">
  </column></property>
  <property name="customerAddress">
  <column name="address">
  </column></property>
  <property name="customerEmail">
  <column name="email">
  </column></property>
  </class>
</hibernate-mapping>


这里怎么了?为什么它不填充我的数据库?

删除以下元素:

<mapping/>

这会导致日志中出现异常:

配置中的元素未指定属性

我将尝试寻找另一个教程,展示如何使用注释而不是XML文件进行映射,因为

  • 注释要容易得多
  • 注释是映射实体的标准JPA方式