getHibernateTemplate().save 不能写入数据

spring配置文件中的内容如下:<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource... spring配置文件中的内容如下:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="jdbcUrl"
value="jdbc:sqlserver://localhost:1433;DatabaseName=GPSRecord">
</property>
<property name="user" value="sa"></property>
<property name="password" value="sa"></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>
</bean>
<bean id="AlarmTableDAO" class="test.AlarmTableDAO">
<property name="sessionFactory">
<ref bean="sessionfactory" />
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref ="sessionFactory"/>
</bean>
<bean id="AlarmTableDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target" ref="AlarmTableDAO"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>
</beans>
AlarmTableDAOImpl类中有如下代码:
public class AlarmTableDAO extends HibernateDaoSupport implements IAlarmTableDao {
private static final Log log = LogFactory.getLog(AlarmTableDAO.class);
public void save(AlarmTable transientInstance) {
log.debug("saving AlarmTable instance");
try {
getHibernateTemplate().save(transientInstance);log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
}
Hibernate.cfg.xml内容如下:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.-->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=GPSRecord
</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="connection.autocommit">true </property>
<property name="myeclipse.connection.profile">m</property>
<mapping resource="test/AlarmTable.hbm.xml" />
</session-factory>
</hibernate-configuration>
save()函数保存一个对象,我生成一个AlarmTable对象后,调用save(),结果显示:
DEBUG [Thread-1] (AlarmTableDAO.java:33) - saving AlarmTable instance
ERROR [Thread-1] (AlarmTableDAO.java:38) - save failed
java.lang.NullPointerException
at test.AlarmTableDAO.save(AlarmTableDAO.java:35)
at test.thread.run(thread.java:60)
Exception in thread "Thread-1" java.lang.NullPointerException
at test.AlarmTableDAO.save(AlarmTableDAO.java:35)
at test.thread.run(thread.java:60)
展开
 我来答
fujiansf
2010-07-27 · 超过95用户采纳过TA的回答
知道小有建树答主
回答量:291
采纳率:0%
帮助的人:184万
展开全部
<property name="hibernateProperties">
没有指定映射文件吧
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式