日期:2014-05-17  浏览次数:20692 次

SSH插入数据,报空指针???
SSH做了一个小例子,save的时候报空指针,主要是hibernate封装jdbc时报空指针,代码如下:
ACTION:UserService userService = new UserService();
UserDao userDao = new UserDao();
User user = new User();
user.setName(name);
user.setPassword(password);
user.setEmail(email);
user.setPhone(phone);
user.setCompany(company);
user.setAddress(address);
user.setCreateTime(new Date());
user.setModificationTime(new Date());
37行------------- userDao.save(user)-------------------------------------------
暂时没调用service,dao的代码:
@Repository
public class UserDao extends HibernateDao<User> {
}
-------------------------------------------
HibernateDao里面的save部分代码:
public void save(T o) {
getHibernateTemplate().saveOrUpdate(o);
}
--------------------------------------------
spring.xml:
<context:annotation-config />
<context:component-scan base-package="com.shop.dao" />
<context:component-scan base-package="com.shop.service" />
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>

  <property name="minPoolSize" value="5"/>
  <property name="maxPoolSize" value="30"/>
  <property name="acquireIncrement" value="5"/>
  <property name="maxIdleTime" value="120"/>
  <property name="maxStatements" value="100"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.shop.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
  <prop key="hibernate.current_session_context_class">thread</prop>
   
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
<prop key="hibernate.hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.autoReconnect">true</prop>
</props>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<!-