Bonjour à tous, je suis entrian de mettre en place la solution suivante :
- Serveur JBoss
- Annotation Hibernate pour les entités
- Injection de bean
- Transaction par AOP
- Application web service avec RestEasy (en couche n-tiers => service / dao / entités)

Deux problèmes s'opposent à moi :
- 1er problème : J'ai un service ProfileServiceImpl qui a un bean IProfileDao permettant d'accéder à la DAO. Lorsque je lance mon serveur JBoss, le bean est bien instancié. Mon service est bien exposé en REST. Lorsque j'interroge mon service, celui-ci me crée une nouvelle instance de ma classe service et cela fait que mon bean IProfileDao est nul. Comment faire pour récupéré le bean instancié précédemment ?

- 2ème problème : J'ai mis en place la gestion de la transaction via mon ApplicaitonContext.xml avec de l'AOP. Le cheminement est le suivant :
* Mon service via mon bean dao appel ma dao
* Ma dao fait un getHibernateTemplate().getSessionFactory().getCurrentSession() puis un persist
Je n'ai aucune erreur mais rien n'est inséré en base de données. Cela signifie que la transaciton n'a pas eu lieu ou n'a pas commit.

J'ai lu pas mal de forum mais je n'ai pas trouvé la solution à mon problème. J'espère pouvoir la trouvé ici.

Voici les fichiers et informations nécessaires :
ApplicationContext.xml
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
 
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        ...
    </bean>
 
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
				<prop key="hibernate.search.autoregister_listeners">false</prop>
				<prop key="hibernate.show.sql">true</prop>
				<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
			</props>
		</property>
		<property name="annotatedClasses">
			<list>
<value>com.meryodev.hiahws.entitites.ProfileRelation</value>
...				<value>com.meryodev.hiahws.entitites.ProfileMedia</value>
			</list>
		</property>
	</bean>
 
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
 
	<tx:advice id="serviceTxAdvice" transaction-manager="transactionManager">
     <tx:attributes>
       <tx:method name="find*" propagation="REQUIRED" read-only="true" />
       <tx:method name="*" propagation="REQUIRED" />
     </tx:attributes>
   </tx:advice>
 
   <aop:config>
     <aop:pointcut id="serviceMethods" expression="execution(* com.meryodev.hiahws.services.impl.*Service*.*(..))" />
     <aop:advisor advice-ref="serviceTxAdvice" pointcut-ref="serviceMethods" />
   </aop:config>
 
	<bean id="IProfileDao" class="com.meryodev.hiahws.dao.impl.ProfileDaoImpl">
		<property name="sessionFactory"><ref bean="sessionFactory" /></property>
	</bean>
 
	<bean id="IProfileServiceTarget" class="com.meryodev.hiahws.services.impl.ProfileServiceImpl">
		<property name="IProfileDao"><ref bean="IProfileDao" /></property>
	</bean>
ProfileServiceImpl.java
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
 
public class ProfileServiceImpl implements IProfileService {
private static IProfileDao iProfileDao = null;
 
	public void setIProfileDao(IProfileDao iProfile) {
		iProfileDao = iProfile;
		logger.info(iProfileDao);
	}
 
@Override
	public Response createProfile(Profile profile) {
 
...
			iProfileDao.createProfile(profile);
...
	}
}
ProfilDaoImpl
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
public class ProfileDaoImpl extends HibernateDaoSupport implements IProfileDao {
...
public void createProfile(Profile profile) {
		...
			Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
			session.persist(profile);
	...
}
...
}
Merci d'avance pour votre aide.