Ich versuche, eine Entität in die Datenbank mit Kamel Jpa-Komponente zu schreiben. Das Problem ist, dass ich bekommecamel-jpa "keine Transaktion ist in Bearbeitung"
javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3428)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1395)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1391)
at org.apache.camel.component.jpa.JpaProducer$1.doInTransaction(JpaProducer.java:85)
Die persistente Einheit ist analysiert Flosse und die Tabelle erstellt. Hier ist persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="hibernate.connection.username" value="user" />
<property name="hibernate.connection.password" value="pass" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
ich einen Test erstellt eine Einheit zu schreiben:
/**
* Created by moritz on 16.09.2016.
*/
public class JpaTest extends CamelTestSupport {
@EndpointInject(uri = "mock:out")
protected MockEndpoint out;
@EndpointInject(uri = "direct:in")
protected DirectEndpoint in;
@EndpointInject()
@Test
public void writeSome() throws Exception {
PartnerFactaEntity e = new PartnerFactaEntity();
e.setNameIrs("huhu");
e.setPartnerId("1");
e.setUsDokumentGueltigBis(new Date());
e.setUsDokumentGueltigVon(new Date());
context.start();
ProducerTemplate template = context.createProducerTemplate();
template.sendBody(in, e);
}
@Before
public void setup() throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
// ((JndiRegistry) context.getRegistry()).bind(
// "EntityManagerFactory", emf);
// ((JndiRegistry) context.getRegistry()).bind("TransactionManager",
// new JpaTransactionManager());
JpaComponent jpaComponent = context.getComponent("jpa", JpaComponent.class);
jpaComponent.setEntityManagerFactory(emf);
JpaTransactionManager taM = new JpaTransactionManager();
taM.setEntityManagerFactory(emf);
jpaComponent.setTransactionManager(taM);
context.addRoutes(new TestRoute());
}
@Override
public boolean isUseRouteBuilder() {
return false;
}
private class TestRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from(in).to("jpa:PartnerFactaEntity").to(out);
}
}
}
Da es keine wirkliche Möglichkeit ist, eine Transaktion in Kamel semantischen ich denke, zu starten und beenden ist das Problem damit verbundene einrichten?
Also, wie das zu beheben?
EDIT
Ich folgte Rat Claus' und fügte hinzu .transacted()
auf die Route. Dies ergibt No bean could be found in the registry of type: PlatformTransactionManager
Dann i diese Zeile Setup-Methode hinzugefügt:
((JndiRegistry)((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("PlatformTransactionManager", taM );
und dies wiederum führt zu javax.persistence.TransactionRequiredException: no transaction is in progress
.
Ich bin mir nicht sicher, was auf JpaComponent zu konfigurieren und was in die Registrierung zu binden.
Inzwischen debuggte ich ein bisschen. Ich überprüfte die Felder in JpaProducer, wo entityManager.flush()
die Ausnahme wirft: trasactionTemplate ist gesetzt "PRPAGATION_REQUIRED, ISOLATION_DEFAULT" mit korrekten JpaTransactionManager.
Es ist transacted() müssen Sie in Ihrem Kamel verwenden, um Camel zu sagen a Transaktion. Siehe die Dokumentation unter: http://camel.apache.org/transactional-client.html –
Ich habe es versucht, aber es hat nicht geholfen - siehe meine Bearbeitung – dermoritz