不一致的hibernate方言错误,用ipconfig / renew消失

时间:2016-10-03 10:10:47

标签: java hibernate jpa c3p0

这是我的第一个问题。我会尝试尽可能具体。

首先,我知道有很多关于这个错误的主题,有些是解决方案,但我的情况有所不同,因为我每次都有这个错误而且在我输入ipconfig后它会消失一段时间/在cmd中续订。所以,现在详细说明。

我在Windows 7中工作。

这是我的数据源配置:

package ...;

import ...;

@Configuration
public class DataSourceConfig {

  @Value("${db.url}") private String url;
  @Value("${db.user}") private String user;
  @Value("${db.pass}") private String pass;
  @Value("${db.poolSize.init}") private int initPoolSize;
  @Value("${db.poolSize.min}") private int minPoolSize;
  @Value("${db.poolSize.max}") private int maxPoolSize;
  @Value("${db.statements.max}") private int maxStatements;
  @Value("${db.idleTime.max}") private int maxIdleTime;
  @Value("${db.checkoutTimeout}") private int checkoutTimeout;

 @Bean
  public DataSource oracleDataSource() throws SQLException {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setJdbcUrl(url);
    dataSource.setUser(user);
    dataSource.setPassword(pass);
    dataSource.setInitialPoolSize(initPoolSize);
    dataSource.setMaxPoolSize(maxPoolSize);
    dataSource.setMinPoolSize(minPoolSize);
    dataSource.setMaxIdleTime(maxIdleTime);
    dataSource.setMaxStatements(maxStatements);
    dataSource.setCheckoutTimeout(checkoutTimeout);

    return dataSource;
  }
}

JPA配置:

package ...;
import ...;

@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
public class JpaConfig {

  @Autowired
  private DataSource dataSource;

  @Value("${is.ddl.enabled}")
  private String isDDLenabled ;

  @Bean
  public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(Boolean.valueOf(isDDLenabled));

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("...");
    factory.setDataSource(dataSource);
    factory.setJpaDialect(new HibernateJpaDialect());
    factory.afterPropertiesSet();
    return factory.getObject();
  }


  @Bean
  public PlatformTransactionManager Here() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(entityManagerFactory());
    return transactionManager;
  }
}

我和Jetty一起跑步。 当我第一次运行它时,它没问题。但经过8-15次运行后,我得到以下结果:

Failed startup of context ...
org.springframework.beans.factory.BeanCreationException:
...
org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.persistence.EntityManagerFactory]: Factory method 'entityManagerFactory' threw exception; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

之后如果我尝试运行该项目,我会在命令行中遇到相同的错误,直到我运行ipconfig / renew命令。之后再次运行8-15次,没有问题。

这里有人遇到过这样的事吗? ipconfig如何影响项目的运行?请帮忙。

1 个答案:

答案 0 :(得分:0)

您正在使用org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter,您应该使用此org.springframework.orm.jpa.vendor.HibernateJpaDialect

HibernateJpaDialect hibernateJpaDialect =new HibernateJpaDialect();

并将工厂对象设置如下:

factory.setJpaVendorAdapter(hibernateJpaDialect);