Spring @Transactional behaviour with only one transactional data source
<p>I have an app that accesses two databases. Obviously, if I need to have a transaction span both DBs, I need to use something like two phase commit. But I don't need this king of guarantee right now, I don't need everything to be transactional. Things can crash or succeed independently, the app can handle it and not end-up in an inconsistent state. </p>

<p>Right now I have a setup like this one (removed interfaces, code, etc to make it as simple as possible to explain):</p>

<p>Two data sources:</p>

<pre><code>&lt;bean id="firstDS" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
    &lt;qualifier value="firstDS" /&gt;
    &lt;property name="jndiName" value="java:comp/env/jdbc/firstDS" /&gt;
&lt;/bean&gt;

&lt;bean id="secondDS" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
    &lt;qualifier value="secondDS" /&gt;
    &lt;property name="jndiName" value="java:comp/env/jdbc/secondDS" /&gt;
&lt;/bean&gt;
</code></pre>

<p>One transaction manager for <strong>only one</strong> of the data sources:</p>

<pre><code>&lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

&lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
    &lt;property name="dataSource" ref="firstDS" /&gt;
&lt;/bean&gt;
</code></pre>

<p>A service:</p>

<pre><code>@Service
@Transactional(propagation = Propagation.REQUIRED)
public class Service {

    @Autowired
    private FirstDao firstDao;

    @Autowired
    private SecondDao secondDao;

    public void updateStuff() {
        firstDao.updateStuff();
        secondDao.updateStuff();
    }
}
</code></pre>

<p>and two DAOs:</p>

<pre><code>@Transactional(propagation = Propagation.MANDATORY)
public class FirstDao {

    @Autowired
    @Qualifier("firstDS")
    private DataSource dataSource;

    public void updateStuff() {
        // updates stuff in the first database using dataSource
    }
}

@Transactional(propagation = Propagation.MANDATORY)
public class SecondDao {

    @Autowired
    @Qualifier("secondDS")
    private DataSource dataSource;

    public void updateStuff() {
        // updates stuff in the second database using dataSource
    }
}
</code></pre>

<p>Now, this runs without problems (or at least none that I could observe) but my questions are: </p>

<ul>
<li>is this safe or does it have any side effects? </li>
<li>How does the second DAO behave since it is transactional but the transaction is for another database? </li>
<li>Should I remove the @Transactional annotation from the second DAO? Will it then behave just like any other method call?</li>
</ul>

<p>I've read the reference and various posts online but I still am not sure about the behavior.</p>