Czesc, mam taki problem. Klasa TestDAOImpl wyglada tak:
public class TestDAOImpl extends HibernateDaoSupport implements TestDAO {
public void deleteAllTest(){
SQLQuery q = getHibernateTemplate().getSessionFactory().getCurrentSession()
.createSQLQuery("" + "TRUNCATE table Test");
}
}
Ale wywala mi to:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Czemu??
moj applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="applicationContextProvider" class="com.test.ApplicationContextProvider" />
<bean id="hibernateDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test_db" />
<property name="username" value="user" />
<property name="password" value="pass" />
</bean>
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="hibernateDataSource" />
<property name="schemaUpdate" value="true" />
<property name="hibernateProperties">
<value>
hibernate.dialect = org.hibernate.dialect.MySQLDialect
show_sql = true
current_session_context_class = thread
</value>
</property>
<property name="annotatedClasses">
<list>
<value>com.entity.Test</value>
</list>
</property>
</bean>
<bean id="testDAOImpl" class="com.dao.TestDAOImpl" lazy-init="true">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
</beans>
Lub moze ktos z Was wie jak inaczej przy pomocy getHibernateTemplate() zrobic truncate na tabeli?
(truncate table Test)
pzdr,
misty