小编xyz*_*xyz的帖子

发生异常后继续进行交易-JPA

我在Spring上使用JPA。我正在尝试批量导入。如果批量导入有问题,那么我想单独插入,如果也失败,那么我想保存到重复表。我为此编写了逻辑,但每次都会收到此错误:

Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
Run Code Online (Sandbox Code Playgroud)

JPA的矿山设置如下:

@Bean(name = "dataSource", destroyMethod = "")
  public DataSource getDataSource() {
    return new JndiDataSourceLookup().getDataSource(props.getDbJndiName());
  }

  @Bean
  public JpaVendorAdapter getHibernateJpaVendorAdapter() {
    return new HibernateJpaVendorAdapter();
  }

  @Bean
  public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryBean() {
    LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean();
    lcemfb.setDataSource(getDataSource());
    lcemfb.setPersistenceUnitName("MyPU");
    lcemfb.setPackagesToScan("com.project");
    lcemfb.setJpaVendorAdapter(getHibernateJpaVendorAdapter());
    lcemfb.setJpaProperties(getHibernateProperties());
    return lcemfb;
  }

  @Bean
  public Properties getHibernateProperties() {
    Properties jpaProperties = new Properties();
    jpaProperties.put(DIALECT, "org.hibernate.dialect.Oracle10gDialect");
    jpaProperties.put(SHOW_SQL, true);
    jpaProperties.put(AUTOCOMMIT, true);
    jpaProperties.put(FORMAT_SQL, true);
    jpaProperties.put(USE_SQL_COMMENTS, true);
    jpaProperties.put(STATEMENT_BATCH_SIZE, 20);
    jpaProperties.put(ORDER_INSERTS, true); …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-transactions

5
推荐指数
2
解决办法
5659
查看次数

AtomicInteger在循环中计算

public final int getAndIncrement() {
for (;;) {
    int current = get();
    int next = current + 1;
    if (compareAndSet(current, next))
        return current;
   }
}
Run Code Online (Sandbox Code Playgroud)

我发现increment方法在循环块中起作用.为什么我们不能在没有任何循环的情况下计算结果?什么是它?

java atomic

0
推荐指数
2
解决办法
757
查看次数

标签 统计

java ×2

atomic ×1

hibernate ×1

jpa ×1

spring ×1

spring-transactions ×1