spring 联合hibernate不能保存数据???
spring 联合hibernate不能保存数据???????????? 程序没报错 我用的数据库是mysql5.0; 高手们,帮我指点一下啊,谢谢了啊
这是我的测试代码:
package springdao;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Springdaotest {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext ctx=
new ClassPathXmlApplicationContext("applicationContext.xml");
BbsuserDAO dao=(BbsuserDAO)ctx.getBean("BbsuserDAO");
Bbsuser user=new Bbsuser();
user.setUsername("lmbmb");
user.setPassword("12323");
System.out.println(user.getUsername());
dao.save(user);
System.out.println(user.getPassword());
}
}
这是Bbsuser.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="springdao.Bbsuser" table="bbsuser" catalog="test">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="increment" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="10" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="10" />
</property>
<property name="age" type="java.lang.String">
<column name="age" length="10" />
</property>
</class>
</hibernate-mapping>
这是applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.
<beans>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="man" name="man_test" class="springtest.Man">
<property name="message">
<value>你好!!aaaa</value>
</property>
</bean>
<bean id="BbsuserDAO" class="springdao.BbsuserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
这是BbsuserDAO.java
package springdao;
import java.util.List;
import org.
import org.
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* A data access object (DAO) providing persistence and search support for
* Bbsuser entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see springdao.Bbsuser
* @author MyEclipse Persistence Tools
*/
public class BbsuserDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(BbsuserDAO.class);
// property constants
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String AGE = "age";
protected void initDao() {
// do nothing
}
public void save(Bbsuser transientInstance) {
log.debug("saving Bbsuser instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Bbsuser persistentInstance) {
log.debug("deleting Bbsuser instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Bbsuser findById(java.lang.Integer id) {
log.debug("getting Bbsuser instance with id: " + id);
try {
Bbsuser instance = (Bbsuser) getHibernateTemplate().get(
"springdao.Bbsuser", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Bbsuser instance) {
log.debug("finding Bbsuser instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Bbsuser instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Bbsuser as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByUsername(Object username) {
return findByProperty(USERNAME, username);
}
public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}
public List findByAge(Object age) {
return findByProperty(AGE, age);
}
public List findAll() {
log.debug("finding all Bbsuser instances");
try {
String queryString = "from Bbsuser";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Bbsuser merge(Bbsuser detachedInstance) {
log.debug("merging Bbsuser instance");
try {
Bbsuser result = (Bbsuser) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Bbsuser instance) {
log.debug("attaching dirty Bbsuser instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Bbsuser instance) {
log.debug("attaching clean Bbsuser instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static BbsuserDAO getFromApplicationContext(ApplicationContext ctx) {
return (BbsuserDAO) ctx.getBean("BbsuserDAO");
}
}
高手们,帮我指点一下啊!!!!!!!!!