我在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;
}
}
# 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
答案 0 :(得分:0)
Hibernate希望底层数据库为给定属性提供自动递增功能,在您的情况下为id
。 IOW,Oracle(您的情况)应支持字段的自动递增功能。 Oracle开始使用12c version提供自动递增功能,并且随着版本的减少,您会收到该异常。