Je teste mais autant ceci fonctionne
1 2 3
| Session session = getSession();
session.delete(obj);
releaseSession(session); |
Si j'hérite de la classe de HibernateDAOSupport
Autant
1 2 3
| public void delete(Object obj) {
getSessionFactory().getCurrentSession().delete(obj);
} |
Ne fonctionne pas, que je dérive de HibernateDAOSupport ou non (en ajoutant un sessionFactory en private si je dérive pas)
Par exemple sur le find
Accounts account = (Accounts) getSessionFactory().getCurrentSession().get(Accounts.class, id);
J'ai l'exception suivante :
1 2 3 4 5
| org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.LocalSessionFactoryBean$TransactionAwareInvocationHandler.invoke(LocalSessionFactoryBean.java:1175)
at $Proxy0.getCurrentSession(Unknown Source)
at net.sf.l2j.loginserver.dao.impl.AccountsDAOHib.findById(AccountsDAOHib.java:49)
at net.sf.l2j.loginserver.dao.AccountsDAOTest.testFindAccount(AccountsDAOTest.java:73) |
Ma configuration est :
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
| <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.timeout">0</prop>
<prop key="hibernate.c3p0.max_statement">100</prop>
<prop key="hibernate.c3p0.idle_test_period">60</prop>
<prop key="hibernate.c3p0.acquire_increment">5</prop>
<prop key="hibernate.c3p0.autocommit">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/net/sf/l2j/loginserver/beans/</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://localhost/l2jdbtest</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="AccountDataDAO" class="net.sf.l2j.loginserver.dao.impl.AccountDataDAOHib">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> |
Une idée ?
Partager