Hi, You can just inject the EntityManagerFactory which is thread safe and then in the methods of your dao create an EntityManager that you only use for this call. Example blueprint.xml below
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/xmlns/jpa/v1.0.0 http://aries.apache.org/schemas/jpa/jpa.xsd http://aries.apache.org/xmlns/transactions/v1.0.0 http://aries.apache.org/schemas/transaction/transactionv10.xsd"> <bean id="workManager" class="be.i8c.batch_nt.work.impl.WorkManager"> <jpa:unit property="emf" unitname="batch_nt" /> </bean> <service id="workManagerService" ref="workManager" auto-export="interfaces"/> </blueprint> -----Original Message----- From: Lukas Stampf [mailto:[email protected]] Sent: woensdag 18 juli 2012 11:25 To: [email protected] Subject: EntityManager Synchronisation Problem Hi all, I am using openjpa and aries blueprint(last deployed SNAPSHOT) on latest Karaf SNAPSHOT. I have a bundle offering a persistence service to my other bundles. My blueprint configuration is the following: <bean id="connectorJPA" class="org.openengsb.persistence.connector.jpabackend.ConnectorJPAPersistenceBackendService"> <tx:transaction method="*" value="Required" /> <jpa:context property="entityManager" unitname="openengsb-connector" /> </bean> <service interface="org.openengsb.core.api.persistence.ConfigPersistenceBackendService"> <service-properties> <entry key="backend.id" value="connector-jpa-persistence" /> </service-properties> <ref component-id="connectorJPA" /> </service> part of the persistence.xml <persistence-unit name="openengsb-connector" transaction-type="JTA"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/openengsb)</jta-data-source> My problem is that I have to put the calls to the entityManager into synchronized(entityManager){} blocks, because the service can get called multiple times at once, leading to synchronisation errors in the entityManager since it is not thread safe. Is there an equivalent to Spring's SharedEntityManagerImpl or any better solution than synchronise manually? kind regards, Lukas Stampf
