Sorry for the crosspost i didn't mean to do it.
Yes your right i used a bad transaction manager i corrected it but i have a new problem i have the following error :No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here. to correct this error i documented myself and i found that i have to use TransactionProxyFactoryBean and that's what i did but i still have the problem here is my context file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!--bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" /-->
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<bean id="implementationProduit" class="akatsuki.domain.service.implProduit">
<property name="productDao" ref="produitDaoHibernate"/>
</bean>
<bean id="produitDaoHibernate" class="akatsuki.domain.repositry.impl.ProduitDaoHibernate">
<property name="sessionFactory" ref="SessionFactory"/>
</bean>
<bean id="traitement" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="TransactionManager"/>
<property name="target" ref="produitDaoHibernate"/>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/cmd</prop>
<prop key="hibernate.connection.username">root</prop>
<prop key="hibernate.connection.password"></prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<bean id="TransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="SessionFactory"/></property>
</bean>
</beans>
and here is the target bean :
Code:
/*
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package akatsuki.domain.repositry.impl;
import akatsuki.domain.model.Produit;
import akatsuki.domain.repositry.ProductDao;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
/**
*
* @author hamza
*/
public class ProduitDaoHibernate implements ProductDao{
private SessionFactory sessionFactory;
public List<Produit> getProduits() {
List<Produit>lst;
lst=new ArrayList<Produit>();
/*Produit p = new Produit();
p.setId(11);
p.setNom("Giggs");
lst.add(p);*/
Session session = sessionFactory.getCurrentSession();
Query req = session.createQuery("select id,nom from Produit");
FileWriter fw=null;
try{
fw = new FileWriter("D:\\n.txt");
fw.write("l");
fw.flush();
fw.close();
}catch(Exception e){
}
int i=0;
for(Iterator it = req.iterate();it.hasNext();){
Produit p = new Produit();
Object[]ligne=(Object[])it.next();
p.setId(Integer.parseInt(ligne[0].toString()));
p.setNom(String.valueOf(ligne[1]));
lst.add(p);
try{
fw.write(String.valueOf(i));
fw.flush();
fw.close();
}
catch(Exception e){
}
}
return lst;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
Correct im if i'am wrong the TransactionProxyFactoryBean serves to wrap a bean so that he can use transaction methods taht's why i specified in the target bean my dao bean. and for the transactionattributes when i do something like that insert* it means every sql statement who begin with insert to be propageted and everything else * to be read-only?