spring+hibernate 没报错,可就是不能插入数据库,急急急!!
代码如下:
测试类:
package com.test;
import com.dao.PersonDao;
import com.po.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class PersonDaoTest {
public static void main(String[] args) throws Exception {
ApplicationContext applicationContext=new FileSystemXmlApplicationContext("WebRoot/WEB-INF/classes/applicationContext.xml");
PersonDao personDao=(PersonDao)applicationContext.getBean("personDaoImpl");
Person person=new Person();
person.setAge(22);
person.setName("xqy1");
System.out.println("导入数据开始.......");
personDao.insert(person);
System.out.println("导入数据结束.......");
}
}
配置文件:Person.hbm.xml
<?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.po.Person" table="person">
<id name="id" type="java.lang.String">
<column name="id" length="32" />
<generator class="uuid.hex"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="name" length="32" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
</class>
</hibernate-mapping>
运行结果:
log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
导入数据开始.......
导入数据结束.......
我用的是mysql,数据库就是没数据,急死俺列!!