mysql - 使用hobernate保存数据到MySQL获取ultraedit

标签 mysql hibernate

我使用hibernate将数据保存到MySQL中,但我使用了ultraedit。

enter image description here

我的代码如下:

@Test
public void testA(){

    Employee emp = new Employee();
    emp.setEmpName("邓海");
    emp.setWorkDate(new Date());

    Configuration conf = new Configuration();
    conf.configure(); 
    SessionFactory sf = conf.buildSessionFactory();
    Session session = sf.openSession();
    Transaction ts = session.beginTransaction();
    session.save(emp);
    ts.commit();
    session.close();
    sf.close();

}

我的 .hbm.xml 如下:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.ypd.a.entity">
    <class name="Employee" table="t_employee">

        <id name="empId" column="id">
        <generator class="native"/>
    </id>

    <property name="empName" column="emp_name"></property>
    <property name="workDate" column="workDate"></property>

</class>
</hibernate-mapping>

我的 hibernate.xml 是:

hibernate-configuration >
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <property name="hibernate.show_sql">true</property>
        <property name="javax.persistence.validation.mode">none</property>
        <mapping resource="Employee.hbm.xml"></mapping>
    </session-factory>

</hibernate-configuration>

编辑

enter image description here

是否有一些我不知道的设置?请告诉我正确的设置。

最佳答案

在你的 sessionFactory 中尝试一下:

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8</property>

与服务器通信时应指定字符集。

关于mysql - 使用hobernate保存数据到MySQL获取ultraedit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742841/

相关文章:

java - 即使添加了 Hibernate,它也没有被导入

mysql - 使用 WHERE 或 ON 进行过滤

mysql - 复杂的删除查询

mysql - 尝试将 MySQL 与 Emacs 结合使用的问题

java - Hibernate 和 Ehcache - 如何确保每个 "select"都通过实体缓存?

java - Spring 4 Web服务HTTP 500 - IllegalStateException : The mapped controller method class is not an instance of the actual controller bean

mysql 选择时间范围和条件

java - Hibernate 对象和 GWT-RPC

java - 返回 DTO 内的另一个实体或 DTO

java - org.hibernate.exception.SQLGrammarException : could not execute statement