Hi All,
For a week or so now I have been trying to amend one or our EJB calls to use spring deeclarative transaction management with hibernate. The idea being to use it in all our EJB's and then hopefully faze out our EJB's!
1 . However I am nearly there but I need to catch duplicate key exceptions and throw my own but I think I have read too many posts and got confused since DataIntegrityViolationException is not being thrown.
2. My config is below but first I would like to say that I have used a hibernate interrceptor in my dao instead of the template as I neeed to use the Hibernate query interface and have used the transactionInterceptor in my EJB impl. Not sure if this is the corrrect way but I I dont know if I am able to combine these somehow to put both in the dao?
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName">
<value>java:comp/env/jdbc/osonetracker-ds</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingResources">
<list>
mapping files .....
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.M ySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate.Hibernate Interceptor">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor .TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributeSource">
<value>com.jspangle.onetracker.service.registratio n.RegistrationService.register=PROPAGATION_REQUIRE D</value>
</property>
</bean>
<bean id="organisationDataAccessorImpl" class="com.jspangle.onetracker.data.access.hiberna te.OrganisationDataAccessor">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="organisationDataAccessor" class="org.springframework.aop.framework.ProxyFact oryBean">
<property name="proxyInterfaces">
<value>com.jspangle.onetracker.data.access.IOrgani sationDataAccessor</value>
</property>
<property name="interceptorNames">
<list>
<value>hibernateInterceptor</value>
<value>organisationDataAccessorImpl</value>
</list>
</property>
</bean>
<bean id="registrationServiceImpl" class="com.jspangle.onetracker.service.registratio n.RegistrationServiceImpl">
<property name="organisationDataAccessor">
<ref bean="organisationDataAccessor"/>
</property>
</bean>
<bean id="RegistrationService" class="org.springframework.aop.framework.ProxyFact oryBean">
<property name="proxyInterfaces">
<value>com.jspangle.onetracker.service.registratio n.RegistrationService</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<value>registrationServiceImpl</value>
</list>
</property>
</bean>
</beans>
Code:
public Long register(Organisation organisation){
Long id = null;
try {
id = (Long)organisationDataAccessor.addOrganisation(org anisation);
} catch (DataIntegrityViolationException e) {
e.printStackTrace();
}
return id;
Sorry to ramble but my questions are:
1. How do I get to trap the exceptions, in my log I am getting JDBCExceptionReporter entries is this correct or should I used SQLExceptionTranslator ? if so how do I without using the HibernateeTemplate.
2. Is my approach ok whereby the hibernate interceptor is applied to the dao and the transacfionInterceptor applied to my EJB impl? Can I merge these?
My head is swimming .. Any help is appreciated.


Reply With Quote