spring+hibernate开发问题!

zhouonline 2006-12-12 11:16:21
我在调试程序时出现以下错误:
HibernateSystemException异常Hibernate.executeHibernateCallback,boolean)行,391.hibernate.save()
spring配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</property>
<property name="url">
<value>
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=myjob;
</value>
</property>
<property name="username">
<value>sa</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>

</props>
</property>
<property name="mappingResources">
<list>

<value>jou/model/people.hbm.xml</value>

</list>
</property>
</bean>
<bean id="StudentDAO" class="jou.model.StudentDAO">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>



</beans>


接口如下:package jou.model;


public interface IStudentDAO {
public void savepeople(people id) ;

}

DAO类:
package jou.model;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


public class StudentDAO extends HibernateDaoSupport implements IStudentDAO{
private SessionFactory sessionFactory;

static Transaction tx = null;
static Logger log = Logger.getLogger(StudentDAO.class);
public void savepeople(people id)
{
this.getHibernateTemplate().save(id);
}



}
main主函数调用StudentDAO
package jou.model;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Test {
public static void main(String ars[]) {
ApplicationContext ctx = new FileSystemXmlApplicationContext("src/applicationContext.xml");
StudentDAO dao = (StudentDAO)ctx.getBean("StudentDAO");
people pe=new people();
pe.setId(1234);
pe.setUser("ffffffffffffffffff");
dao.savepeople(pe);
System.out.println("fffffffffffffffffffffffff");
}

}
其中要补充的是我调用dao的savapeople()函数就出现异常!这是什么原因,大家请帮帮忙!!
...全文
137 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zqpsswh 2006-12-13
  • 打赏
  • 举报
回复
public class StudentDAO extends HibernateDaoSupport implements IStudentDAO{
private SessionFactory sessionFactory;

static Transaction tx = null;
static Logger log = Logger.getLogger(StudentDAO.class);
public void savepeople(people id)
{
this.getHibernateTemplate().save(id);
}



}

去掉 private SessionFactory sessionFactory;

static Transaction tx = null;
zhouonline 2006-12-13
  • 打赏
  • 举报
回复
跟这个无关..我已经调试好..配置文件问题.多了一个空格就不行了..

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧