legacy-knowledge-base
公開されました Sep. 10, 2025

'バインド前のJDBC接続が見つかりました!'という例外が発生します。

written-by

Sergio Alonso

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • 私たちは、共通の外部 データソースを使用するいくつかのカスタムモジュールを持っています。
  • データベーストランザクション内で、 モジュール Aモジュール B を呼び出した場合、以下の例外が発生します:
org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC Connection found! HibernateTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single HibernateTransactionManager for all transactions on a single DataSource, no matter whether Hibernate or JDBC access.
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:484)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.start(DefaultTransactionExecutor.java:139)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:64)
at com.liferay.portal.spring.aop.AopMethodInvocationImpl.proceed(AopMethodInvocationImpl.java:57)
at com.liferay.change.tracking.internal.aop.CTTransactionAdvice.invoke(CTTransactionAdvice.java:80)
at com.liferay.portal.spring.aop.AopMethodInvocationImpl.proceed(AopMethodInvocationImpl.java:57)
at com.liferay.portal.spring.aop.AopInvocationHandler.invoke(AopInvocationHandler.java:49)
.
.
.

Environment

  • DXP 7.3

解決策

  • Liferay DXP は、 HibernateTransactionManagerを使用します。これは HibernateSessionFactoryLiferayDataSourceに基づいて設定されます。

  • このユーザーケースでは、'n'個のモジュールで共有される追加の外部 DataSource ( LiferayDataSourceとは異なる)が存在します。

そして、すべてのモジュールは、独自の セッションファクトリー と独自の トランザクションマネージャを持ち、結果として 'n' トランザクションマネージャ が一意の DataSourceを共有する。

  • エラーを分析すると、 Hibernate は、 ConnectionHolder オブジェクトをデータベース接続として定義しています。 この接続は、ユニークな データソース (すべての 'n' モジュールに共通) から取得されるので、この Hibernate 条件で例外が生成されます:
    https://github.com/spring-projects/spring-framework/blob/v4.3.22.RELEASE/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTransactionManager.java#L479-L489

  • のいずれかで対応することが可能です:

    • オプション 1: 各モジュールは、共通の データソースの代わりに、独自の データソースを持ちます。

    • オプション2: すべての「n」モジュールは、共通の データソースを使用して、一意の トランザクションマネージャ と一意の セッションファクトリを持つ。 このように、モジュール間のトランザクションは、この独自の トランザクション・マネージャーによって管理されます。

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base