Ошибка создания неудовлетворенной зависимости bean-компонента, выраженная через поле sessionFactory - PullRequest
1 голос
/ 07 мая 2020

Я получаю сообщение об ошибке ниже, где говорится, что столбец не существует в таблице SECU. Но проблема в том, что мне действительно не нужен этот столбец в этой таблице, так как мне нужен только этот столбец в таблице NONSECU, на которую есть ссылка только в классе NONSECU.

Есть ли способ избавиться от этого в методе getbean или где-нибудь еще?

`[main] WARN  org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IsmaImp': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in baag.betl.dbimporter.esmatrans.SpringConfiguration: Invocation of init method failed; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [preTradLrgInScaleThrshld] in table [SECU]; nested exception is org.springframework.beans.factory.BeanCreationException: 

@ Configuration @ComponentScan ("baag.betl.dbimporter.Ismatr") @EnableTransactionManagement publi c класс SpringConfiguration {

@Autowired
private Environment env;

@Bean
public DataSource dataSource() {
    return createDatasource("dwh.");
}

private DriverManagerDataSource createDatasource(String propertyPrefix) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(env.getRequiredProperty(propertyPrefix + "driver"));
    dataSource.setUrl(env.getRequiredProperty(propertyPrefix + "jdbc"));
    dataSource.setUsername(env.getRequiredProperty(propertyPrefix + "user"));
    dataSource.setPassword(env.getRequiredProperty(propertyPrefix + "pwd"));
    return dataSource;
}

@Bean
public Properties hibernateProperties() {
    Properties properties = new Properties();
    properties.put(AvailableSettings.DIALECT, env.getRequiredProperty("hibernate.dialect"));
    properties.put(AvailableSettings.SHOW_SQL, env.getRequiredProperty("hibernate.show_sql"));
    properties.put(AvailableSettings.STATEMENT_BATCH_SIZE, env.getRequiredProperty("hibernate.batch.size"));
    properties.put(AvailableSettings.HBM2DDL_AUTO, env.getRequiredProperty("hibernate.hbm2ddl.auto"));
    properties.put(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, env.getRequiredProperty("hibernate.current.session.context.class"));
    return properties;
}

@Bean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) {
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    sessionFactory.setAnnotatedClasses(Secu.class, NonSecu.class);
    sessionFactory.setHibernateProperties(hibernateProperties());
    return sessionFactory;
}

@Bean
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}

}

1 Ответ

1 голос
/ 07 мая 2020

, если вы хотите игнорировать сопоставление столбцов для какого-либо поля, просто объявляйте их как Transient

Вот так:


@Entity
@Table(name = "SECU")
public class SECU implements Serializable {

    @Transient
    protected BigDecimal preTradLrgInScaleThrshld;

Это поле не будет сохраняться и всегда будет иметь нулевое значение после загрузки.

...