Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring-jpa 整合 #124

Open
TarryHoo opened this issue Sep 7, 2020 · 4 comments
Open

spring-jpa 整合 #124

TarryHoo opened this issue Sep 7, 2020 · 4 comments

Comments

@TarryHoo
Copy link

TarryHoo commented Sep 7, 2020

@liuyangming 大佬,有个问题请教下.

最近在做springcloud 和 Jpa 整合.
请求后报错

Caused by: java.sql.SQLException: Illegal operation!
	at org.bytesoft.bytejta.supports.jdbc.LogicalConnection.setAutoCommit(LogicalConnection.java:83) ~[bytejta-core-0.5.0-BETA8.jar:na]
	at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.begin(AbstractLogicalConnectionImplementor.java:67) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
	... 204 common frames omitted

配置如下

  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties.hibernate.format_sql: true
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect  
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: org.apache.commons.dbcp2.BasicDataSource

版本如下

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
</parent>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.3.10.Final</version>
</dependency>

报错的代码是AbstractLogicalConnectionImplementor.begin()

@Override
public void begin() {
	try {
		if ( !doConnectionsFromProviderHaveAutoCommitDisabled() ) {
			log.trace( "Preparing to begin transaction via JDBC Connection.setAutoCommit(false)" );
			getConnectionForTransactionManagement().setAutoCommit( false );
			log.trace( "Transaction begun via JDBC Connection.setAutoCommit(false)" );
		}
		status = TransactionStatus.ACTIVE;
	}
	catch( SQLException e ) {
		throw new TransactionException( "JDBC begin transaction failed: ", e );
	}
}
@liuyangming
Copy link
Owner

你这个事务走的不是byteTCC的事务管理器,可能走了HibernateTransactionManager。byteTCC针对jpa的集成,请参考ByteTCC-sample/springboot-sample/sample-provider,具体配置看一下这几个类:
1、SpringBootProviderBootstrap: 留意一下@EnableJpaRepositories注解的配置;
2、ProviderConfig: 留意LocalContainerEntityManagerFactoryBean的配置;
3、META-INF/persistence.xml;

@TarryHoo
Copy link
Author

TarryHoo commented Sep 7, 2020

你这个事务走的不是byteTCC的事务管理器,可能走了HibernateTransactionManager。byteTCC针对jpa的集成,请参考ByteTCC-sample/springboot-sample/sample-provider,具体配置看一下这几个类:
1、SpringBootProviderBootstrap: 留意一下@EnableJpaRepositories注解的配置;
2、ProviderConfig: 留意LocalContainerEntityManagerFactoryBean的配置;
3、META-INF/persistence.xml;

好的,多谢大佬解答.我去看下

@TarryHoo
Copy link
Author

TarryHoo commented Sep 8, 2020

@liuyangming 大佬
昨晚测试了下, 不支持springboot 2.1.X
2.1.X的springboot DataSourceInitializedPublisher 做了些改动.
如下是我整合到2.1.X sb 的修改
image

@liuyangming
Copy link
Owner

好的,感谢反馈。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants