G
Gast2
Gast
Ich hab einen TransaktionManager als OSGi Service registriert. Damit ich im business bundle die Transaktionen eröffnen kann wenn ich im bean eine init methode angebe kann diese keine Transaktion aufmachen?! Ist das normal hab in der Doku dazu nichts gefunden oder etwas übersehen?
Wenn ich es jedoch im gleichen Bundle das mache ist das kein Problem
Wenn ich den Service und die Methode normal aufrufe gibts es auch keinerlei Probleme die Transaktion wird sauber geöffnet
osgi.xml
[XML]
<osgi:reference id="transactionManager" interface="org.springframework.transaction.support.ResourceTransactionManager"></osgi:reference>
<osgi:reference id="personDaoRef" interface="org.java.forum.sample.dao.PersonDao"></osgi:reference>
[/XML]
context.xml
[XML]
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context http://www.springframework.org/schema/context/spring-context.xsd
Index of /schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="personService" class="org.java.forum.sample.business.internal.PersonServiceImpl" init-method="consume">
</bean>
</beans>
[/XML]
DAO
osgi xml
[XML]
<?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
sgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Index of /schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd">
<osgi:reference id="dataSourceRef" interface="javax.sql.DataSource" cardinality="1..1" filter="(name=h2DataSource)"/>
<osgi:service id="transactionManagerService" ref="transactionManager" interface="org.springframework.transaction.support.ResourceTransactionManager"></osgi:service>
<osgi:service id="personDaoService" ref="personDao" interface="org.java.forum.sample.dao.PersonDao"></osgi:service>
</beans>
[/XML]
context.xml
[XML]
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean>
<!-- DAO -->
<bean id="personDao" class="org.java.forum.sample.dao.internal.DefaultPersonDao" init-method="init"></bean>
</beans>
[/XML]
Wenn ich es jedoch im gleichen Bundle das mache ist das kein Problem
Wenn ich den Service und die Methode normal aufrufe gibts es auch keinerlei Probleme die Transaktion wird sauber geöffnet
Java:
public class PersonServiceImpl implements PersonService{
@Autowired
private PersonDao personDao;
@Transactional(propagation=Propagation.REQUIRED)
public Person consume() {
return personDao.insert(person);
}
}
[XML]
<osgi:reference id="transactionManager" interface="org.springframework.transaction.support.ResourceTransactionManager"></osgi:reference>
<osgi:reference id="personDaoRef" interface="org.java.forum.sample.dao.PersonDao"></osgi:reference>
[/XML]
context.xml
[XML]
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context http://www.springframework.org/schema/context/spring-context.xsd
Index of /schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="personService" class="org.java.forum.sample.business.internal.PersonServiceImpl" init-method="consume">
</bean>
</beans>
[/XML]
DAO
Java:
public class DefaultPersonDao implements PersonDao {
@PersistenceContext
private EntityManager entityManager;
@Override
@Transactional(propagation=Propagation.MANDATORY)
public Person insert(Person person) {
entityManager.merge(person);
}
@Transactional(propagation=Propagation.REQUIRED)
public void init() {
Person person = new Person();
person.setName("Name");
person.setSurname("Test");
insert(person);
}
}
osgi xml
[XML]
<?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
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Index of /schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd">
<osgi:reference id="dataSourceRef" interface="javax.sql.DataSource" cardinality="1..1" filter="(name=h2DataSource)"/>
<osgi:service id="transactionManagerService" ref="transactionManager" interface="org.springframework.transaction.support.ResourceTransactionManager"></osgi:service>
<osgi:service id="personDaoService" ref="personDao" interface="org.java.forum.sample.dao.PersonDao"></osgi:service>
</beans>
[/XML]
context.xml
[XML]
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean>
<!-- DAO -->
<bean id="personDao" class="org.java.forum.sample.dao.internal.DefaultPersonDao" init-method="init"></bean>
</beans>
[/XML]