【问题标题】:Hibernate IdentityColumnSupportImpl Does Not Support Identity Key GenerationHibernate IdentityColumnSupportImpl 不支持身份密钥生成
【发布时间】:2019-04-04 19:12:30
【问题描述】:

我在 spring boot 项目中有两个不同的数据源。数据源的模式名称之一是欺诈,另一个是测试。当我尝试将对象插入表中时,出现错误,例如

java.lang.IllegalArgumentException: org.hibernate.dialect.identity.IdentityColumnSupportImpl does not support identity key generation

我试过这个来解决我的问题

org.hibernate.dialect.OracleDialect does not support identity key generation

但是这个给出了一个错误,例如

ORA-02289: sequence does not exist

谢谢

控制器

            if (channel.isAnyConvertionFailed()) {
                FraudChannelException fce = new FraudChannelException(/*Params*/);
                fraudChannelExceptionRepository.save(fce);
            }

            //Check if any mandatory fields are empty
            if (/*condition*/){
                FraudChannelException fce = new FraudChannelException(/*Params*/);
                fraudChannelExceptionRepository.save(fce);

                return ExceptionConfiguration.handleMissingFieldError(message);
            }

存储库

@Repository
public interface FraudChannelExceptionRepository extends CrudRepository<FraudChannelException, Integer> {

}

实体

@Entity
@Table(name="fraud_channel_exceptions", schema = "fraud")
public class FraudChannelException implements Serializable {
    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;
    //more fields

    public FraudChannelException(/*PARAMS*/) {
        //init something
    }

    public FraudChannelException(/*PARAMS*/) {
        //init something
    }

    public FraudChannelException(/*PARAMS*/) {
        //init something
    }

    public FraudChannelException() {
    }

    //Getter Setter
}

配置

@Configuration
@PropertySource({ "classpath:application.properties" })
@EnableJpaRepositories(basePackages = "com.ykb.frd.fraudcore.schema.fraud.repo",entityManagerFactoryRef = "entityManager",transactionManagerRef = "transactionManager")
public class FraudConfig{
    @Autowired
    private Environment env;

    @Bean
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManager() {
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(dataSource());
        em.setPackagesToScan("com.ykb.frd.fraudcore.schema.fraud.domain");

        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        em.setJpaVendorAdapter(vendorAdapter);
        HashMap<String, Object> properties = new HashMap<>();
        properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
        properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
        em.setJpaPropertyMap(properties);

        return em;
    }

    @Primary
    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource= new DriverManagerDataSource();
        dataSource.setDriverClassName(env.getProperty("fraud.datasource.driverClassName"));
        dataSource.setUrl(env.getProperty("fraud.datasource.url"));
        dataSource.setUsername(env.getProperty("fraud.datasource.username"));
        dataSource.setPassword(env.getProperty("fraud.datasource.password"));

        return dataSource;
    }

    @Primary
    @Bean
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager transactionManager= new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManager().getObject());
        return transactionManager;
    }
}

APPLICATION.PROPERTIES

# EBNKTST - NDVLIVE
ndvlive.datasource.url=jdbc:oracle:thin:@//URL
ndvlive.datasource.username=//USERNAME
ndvlive.datasource.password=//PASSWORD
ndvlive.datasource.driverClassName=oracle.jdbc.driver.OracleDriver

# EBNKDEV - FRAUD
fraud.datasource.url=jdbc:oracle:thin:@//URL
fraud.datasource.username=//USERNAME
fraud.datasource.password=//PASSWORD
fraud.datasource.driverClassName=oracle.jdbc.driver.OracleDriver

# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.hibernate.SQL=debug

【问题讨论】:

    标签: java oracle hibernate spring-boot


    【解决方案1】:

    Hibernate 期望底层数据库为给定属性提供自动增量功能,在您的情况下是id。 IOW,Oracle(您的情况)应该支持字段的自动增量功能。 Oracle 开始为 12c version 提供自动增量功能,并且由于您的版本较低,您会遇到该异常。

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多