spring+hibernate 没报错,可就是不能插入数据库,急急急!!

09-04-04 Jxqy
代码如下:

测试类:

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,数据库就是没数据,急死俺列!!

freebox
2009-04-04 16:51
请检查事务配置,或更改提交模式。

Jxqy
2009-04-05 17:10
困扰了我两天的问题终于解决了,我没申明提交事务的代理。框架的整合对我像我这样的新手还真是不简单啊,从中我加深了对框架的更深一层次的理解,不错不错,以前是大大滴痛苦,现在是大大滴爽啊,呵呵!谢了,前辈!

[该贴被Jxqy于2009-04-05 17:11修改过]

Jxqy
2010-12-24 11:14
一年之后再来逛逛,感觉真的有很大不同,什么都变了

猜你喜欢