2016-04-28 3 views
0

Der Rollback in meiner Transaktion funktioniert nicht (Spring 3.1). Ich habe versucht, meine Konfiguration XML-Datei, wie here, aber ohne Ergebnis zu bearbeiten. Hier meine XML-Datei:Spring @Transactional configuring xml

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns="http://www.springframework.org/schema/beans" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xmlns:aop= "http://www.springframework.org/schema/aop" 
     xmlns:tx= "http://www.springframework.org/schema/tx" 
     xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
     xsi:schemaLocation=" 
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc.xsd 
       http://www.springframework.org/schema/jee 
       http://www.springframework.org/schema/jee/spring-jee-3.1.xsd 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans.xsd 
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
       "> 

     <jee:jndi-lookup id="dataSourceUsrAppe1" jndi-name="jdbc/ZhabDS"/> 

     <bean id="utentiDAO" class="it.dao.UtentiDAO"> 
      <property name="dataSourceUsrAppe1"> 
       <ref bean="dataSourceUsrAppe1"/> 
      </property> 
     </bean> 
<!-- doesn't work with this: 
     <tx:annotation-driven transaction-manager="txManager"/> 
      <property name="dataSourceUsrAppe1"> 
       <ref bean="dataSourceUsrAppe1"/> 
      </property> 
     </bean> 
    </beans> 
--> 
</beans> 

Sollte ich einen Transaktionsmanager hier hinzufügen?

Hier ist mein Service:

@Service 
public class UtentiService { 
    @Autowired 
    private UtentiDAO utentiDAO; 

    @Transactional(rollbackFor={Exception.class}, propagation=Propagation.REQUIRED) 
    public boolean createUser(Zhabuten user) throws Exception 
    { 
      long idPrincipale; 
      idPrincipale = utentiDAO.insert(user, utentiDAO.query1); 
      idPrincipale = utentiDAO.insert(user, utentiDAO.query2); 

      if (idPrincipale!=0) throw new java.lang.Exception(); 

      idPrincipale = utentiDAO.insert(user, utentiDAO.query3); 
     return false; 
    } 
} 

Die Ausnahme richtig geworfen wird, es von der Steuerung eingefangen ist und die Datenbank nicht rollbacked. Vermisse ich irgendeine Konfiguration in der XML?

+1

Woher kommt Ihr Transaktionsmanager? –

+0

haben Sie die Protokolle überprüft? Startet und begeht die Transaktion? –

+0

Ich habe nicht verstanden, wie man es konfiguriert. Sollte ich das entfernen? Accollativo

Antwort

2

Verwenden Sie die folgende XML-Konfiguration.

<!-- Enable Annotation based Declarative Transaction Management --> 
<tx:annotation-driven proxy-target-class="true" 
    transaction-manager="transactionManager" /> 

<!-- Creating TransactionManager Bean, since JDBC we are creating of type 
    DataSourceTransactionManager --> 
<bean id="transactionManager" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
    <property name="dataSource" ref="dataSourceUsrAppe1" /> 
</bean> 
+0

Danke, das funktioniert! Seltsamerweise habe ich gerade einen neuen seltsamen Popup-Fehler von Eclipse im Debug-Modus bekommen (auch nachdem ich alle alten Breakpoints bereinigt habe): Kann den Breakpoint nicht installieren it.service.UentiService $$ ... CGLIB ... $$ someHEXnumber fällig zu fehlenden Zeilencompilerattributen. Ändern Sie die Compileroption, um Zeilennummernattribute zu generieren. Grund: Informationen zur fehlenden Zeilennummer. – Accollativo