我使用hibernate将数据保存到MySQL中,但我使用了ultraedit。
我的代码如下:
@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>
编辑
是否有一些我不知道的设置?请告诉我正确的设置。
最佳答案
在你的 sessionFactory 中尝试一下:
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</property>
与服务器通信时应指定字符集。
关于mysql - 使用hobernate保存数据到MySQL获取ultraedit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742841/