我有这个问题:“没有绑定到线程的休眠会话,并且配置不允许在这里创建非事务性会话”。我正在使用 spring + hibernate 3。我已经在其他问题中检查过这一点,但它们并没有解决我的问题。在这里,我的 Spring 的 applicationContext。
`<bean id="ServGenerico" class="servico.AbsServicoGenerico" />
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="${jdbc.driver}" p:jdbcUrl="${jdbc.url}" p:user="${jdbc.username}"
p:password="${jdbc.password}" p:max PoolSize="10" p:minPoolSize="5" p:maxStatements="0" destroy-method="close">
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="dao" />
<context:component-scan base-package="dao.impl" />
<context:component-scan base-package="servico" />
<bean id="grupoDeAcaoDao" class="dao.impl.GrupoDeAcaoDao" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="dados" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</prop>
--><!-- <prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.min_size">2</prop>
<prop key="hibernate.c3p0.timeout">5000</prop>
<prop key="hibernate.c3p0.max_statements">10</prop>
<prop key="hibernate.c3p0.idle_test_period">3000</prop>
<prop key="hibernate.c3p0.acquire_increment">2</prop> -->
<!-- <prop key="hibernate.transaction.jta.platform">
org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform
</prop> -->
</props>
</property>
</bean>`
我的服务
@Service
@Transactional
public class ServGrupoDeAcao extends AbsServicoGenerico<GrupoDeAcao>
{
public ServGrupoDeAcao()
{
super();
setDao(new GrupoDeAcaoDao());
}
public ServGrupoDeAcao(Class<?> clazz)
{
super(clazz);
}
/*@Autowired
@Qualifier("grupoDeAcaoDao")
public void setDao(GrupoDeAcaoDao dao)
{
super.setDao(dao);
}*/
}
还有我的 DAO
@Repository
@Transactional
public class GrupoDeAcaoDao extends AbsDao<GrupoDeAcao, Long>
{
@Override
public boolean equals(Object object)
{
// TODO Auto-generated method stub
return false;
}
@Override
public int hashCode()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public Object executarConsultaPersonalizada(NomeMetodo nome,
Parametros parametros)
{
// TODO Auto-generated method stub
return null;
}
public boolean daoCompativel(Class<?> clazz)
{
return GrupoDeAcao.class.equals(clazz);
}
AbsDao 类是一个通用类,在您的方法中具有保存、更新 e 等。并且此类具有 @Repository 和 @Transactional 注释