org.hibernate.service.UnknownUnwrapTypeException:无法解包到请求的类型[javax.sql.DataSource]

时间:2017-06-16 17:46:23

标签: java spring hibernate dependency-injection

运行我的应用程序时遇到此错误:org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]

我的配置类:

@Configuration
@PropertySource("classpath:META-INF/spring/jdbc.properties")
public class HibernateConfig {

    @Autowired
    private Environment env; 

    @Bean(name="dataSource")
    public DataSource getDataSource() throws PropertyVetoException{
        ComboPooledDataSource dataSource = new ComboPooledDataSource();                              
        dataSource.setDriverClass(env.getProperty("db.driverClass"));          
        dataSource.setJdbcUrl(env.getProperty("db.jdbcUrl"));
        dataSource.setUser(env.getProperty("db.user"));                               
        dataSource.setPassword(env.getProperty("db.password"));                               
        dataSource.setMaxPoolSize(50);                               
        dataSource.setMinPoolSize(5);                               
        dataSource.setMaxConnectionAge(1800);                             
        dataSource.setMaxIdleTime(1800);                               
        dataSource.setAutoCommitOnClose(false);                               
        dataSource.setInitialPoolSize(5);  

        return dataSource;
    }  

    @Bean(name="sessionFactory")
    @Scope("singleton")
    public LocalSessionFactoryBean getSessionFactory(DataSource dataSource){
        LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
        Properties hibernateProperties = new Properties();                               
        hibernateProperties.setProperty("hibernate.dialect", env.getProperty("db.dialect"));                                                 
        hibernateProperties.setProperty("hibernate.jdbc.batch_size", "0");                               
        hibernateProperties.setProperty("c3p0.acquire_increment", "1");                           
        localSessionFactoryBean.setHibernateProperties(hibernateProperties);

        return localSessionFactoryBean;
    }              

     @Bean(name="transactionManager")
     public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory){
         HibernateTransactionManager transactionManager = new HibernateTransactionManager();
         transactionManager.setSessionFactory(sessionFactory);

         return transactionManager;
    }
}

我实际上遇到了thread,它讨论了同样的问题。但是我想知道它是否是hibernate5中的某种尚未修复的错误或者是否与其他内容有关。提前谢谢。

0 个答案:

没有答案