创建通过字段sessionFactory表示的bean不满意的依赖项时出错

问题描述 投票:0回答:1

我在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: 

@配置@ComponentScan(“ baag.betl.dbimporter.Ismatr”)@EnableTransactionManagement公共类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;
}

}

[SECU和NONSECU类:

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


    protected BigDecimal preTradLrgInScaleThrshld;


    protected LocalDateTime CreDt;
    protected String fullnm;


    public String getFullNm() {
        return fullnm;
    }

    public LocalDateTime getCreDt() {
        return CreDt;
    }

    public void setCreDt(LocalDateTime CreDt) {
        this.CreDt = CreDt;
    }

    public void setFullNm(String fullnm) {
        this.fullnm = fullnm;
    }

}



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


    protected BigDecimal preTradLrgInScaleThrshld;


    protected LocalDateTime CreDt;
    protected String fullnm;


    public String getFullNm() {
        return fullnm;
    }

    public LocalDateTime getCreDt() {
        return CreDt;
    }

    public void setCreDt(LocalDateTime CreDt) {
        this.CreDt = CreDt;
    }

    public void setFullNm(String fullnm) {
        this.fullnm = fullnm;
    }

    public BigDecimal getPreTradLrgInScaleThrshld() {
        return preTradLrgInScaleThrshld;
    }

    public void setPreTradLrgInScaleThrshld(BigDecimal preTradLrgInScaleThrshld) {
        this.preTradLrgInScaleThrshld = preTradLrgInScaleThrshld;
    }
}
java spring exception javabeans
1个回答
0
投票

如果要忽略某些字段的列映射,只需将其声明为Transient

喜欢这个:


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

    @Transient
    protected BigDecimal preTradLrgInScaleThrshld;

此字段将不会保留,并且在加载后始终为空值。

© www.soinside.com 2019 - 2024. All rights reserved.