的applicationContext.xml
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/rksambari"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="mysessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>/hbm/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.autocommit">true</prop>
</props>
</property>
</bean>
<bean id="template" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="mysessionFactory"></property>
<property name="checkWriteOperations" value="false"/>
</bean>
<bean id="basePersistence" class="com.rksambari.common.basedao.BasePersistenceService">
<property name="template" ref="template"></property>
</bean>
以下是我要插入db
的Java文件public class BasePersistenceService{
HibernateTemplate template;
public void setTemplate(HibernateTemplate template) {
this.template = template;
}
@Transactional(readOnly = false)
public void save(User user){
template.save(user);
template.flush();
}}
保留所有hbm文件和Java pojo文件都没问题。我希望我在applicationContext.xml文件中做错了。请帮我解决这个问题。提前谢谢。