E
E
Eugenue Cesarevich2020-12-23 15:02:02
Java
Eugenue Cesarevich, 2020-12-23 15:02:02

Is it possible to work on JDBC and DATAJPA at the same time?

To work with the database, I use Spring DataJpa and, accordingly, JpaTransactionManager :

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
              p:entityManagerFactory-ref="entityManagerFactory"/>
I also want to work directly with the database via JDBC. However, JDBC needs another transaction manager - DataSourceTransactionManager :
<bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>


How can I solve this problem? Is it even possible to work simultaneously using DataJpa and JDBC in one application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2020-12-23
@cot_shaurma

Yes, it is possible, but it is very bad! JPA generally caches data and queries, while JDBC does not. As a result, it is possible to run into trouble, especially if you made an update via JDBC and immediately after that, a selection via JPA. You can get Schrödinger's cat....
And why, if JPA has createNativeQuery (damn, I still remember something...) - https://thorben-janssen.com/jpa-native-queries/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question