bonjour a tout , j ai un probleme de session avec hibernate
et voici mon codeorg.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:299)
at $Proxy0.getCurrentSession(Unknown Source)
at retrieveByCriteria(AbstractHibernateDao.java:111)
at retrieveByCriteria(AbstractHibernateDao.java:95)
at retrieveEntriesByCriteria(HibernateEntryDao.java:81)
at testRetrieveEntriesByCriteria(HibernateEntryDaoTest.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
et mon fichier spring
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 package database; import java.io.File; import java.io.FileInputStream; import java.net.MalformedURLException; import java.util.List; import junit.framework.TestCase; import org.dbunit.IDatabaseTester; import org.dbunit.JdbcDatabaseTester; import org.dbunit.PropertiesBasedJdbcDatabaseTester; import org.dbunit.database.IDatabaseConnection; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; import org.springframework.context.support.ClassPathXmlApplicationContext; import Entry; import EntrySearchCriteria; public class HibernateEntryDaoTest extends TestCase { private IDatabaseTester databaseTester; IEntryDao entryDao; public HibernateEntryDaoTest(String name) throws Exception { super(name); } protected void setUp() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "spring-fbi-configTest.xml"); entryDao = (IEntryDao) ctx.getBean("dao.entry"); System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, "org.hsqldb.jdbcDriver"); System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, "jdbc:hsqldb:fbiBpsa"); System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, "SA"); System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, ""); databaseTester = new PropertiesBasedJdbcDatabaseTester(); IDatabaseConnection connectionHsql = databaseTester.getConnection(); databaseTester.setDataSet(getDataSet()); // will call default setUpOperation databaseTester.onSetup(); } protected IDataSet getDataSet() throws Exception { return new FlatXmlDataSetBuilder().build(new FileInputStream( ("src\\test\\resources\\full.xml"))); } public void testRetrieveEntriesByCriteria() throws MalformedURLException, DataSetException { EntrySearchCriteria searchCriteria = new EntrySearchCriteria(); List<Entry> entriesListResult = entryDao .retrieveEntriesByCriteria(searchCriteria); assertEquals(entriesListResult.size(),29); IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new File( "expectedDataSet.xml")); } protected void tearDown() throws Exception { // will call default tearDownOperation databaseTester.onTearDown(); } }
pourtant j ai bel et bien une transaction associe a mon dao
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd " > <!--//////////////////////////////////////////////////////////////////////////--> <!--////////////////////////////// Placeholders //////////////////////////////--> <!--//////////////////////////////////////////////////////////////////////////--> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="propertyConfigurer" > <property name="location" value="spring-fbiTest.properties"/> </bean> <!--//////////////////////////////////////////////////////////////////////////--> <!--////////////////////////// Data Access Objects ///////////////////////////--> <!--//////////////////////////////////////////////////////////////////////////--> <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="ds.fbi" > <property name="driverClassName" value="${ds.fbi.driver}"/> <property name="password" value="${ds.fbi.password}"/> <property name="url" value="${ds.fbi.url}"/> <property name="username" value="${ds.fbi.username}"/> </bean> <bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" destroy-method="destroy" id="sf.fbi" > <property name="dataSource" ref="${sf.fbi.datasource}"/> <property name="hibernateProperties"> <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop> <prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop> <prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop> <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.dialect">${sf.fbi.dialect}</prop> <prop key="hibernate.hbm2ddl.auto">${fbi.autocreate}</prop> <prop key="hibernate.jdbc.batch_size">20</prop> <prop key="hibernate.show_sql">false</prop> </props> </property> </bean> </property> <property name="mappingResources"> <list> <value>hibernate/Entry.hbm.xml</value> </list> </property> </bean> <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="tm.fbi" > <property name="sessionFactory" ref="sf.fbi"/> </bean> <tx:advice id="ta.fbi" transaction-manager="tm.fbi" > <tx:attributes> <tx:method name="create"/> <tx:method name="createOrUpdate"/> <tx:method name="delete"/> <tx:method name="retrieve*"/> <tx:method name="retrieveEntriesByCriteria"/> <tx:method name="test*"/> <tx:method name="update"/> <tx:method name="clearPrices"/> </tx:attributes> </tx:advice> <bean abstract="true" class="AbstractHibernateDao" id="abstractHibernateDao.fbi" > <property name="sessionFactory" ref="sf.fbi"/> </bean> <bean class="HibernateEntryDao" id="dao.entry" parent="abstractHibernateDao.fbi" /> </beans>
voir les truc en gras.
Est ce qu il y a une personne qui peut m aide merci
Partager