Home  >  Forum  >  Spring
Post New Query

Caused by: org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]


joined on
August 11,2014
Asked on May 16,2016
Hi,
I am integrating spring MVC and hibernate using javaconfig.
I am getting following error. Any clue?


Caused by: org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.unwrap(UserSuppliedConnectionProviderImpl.java:55)
at org.springframework.orm.hibernate4.SessionFactoryUtils.getDataSource(SessionFactoryUtils.java:106)
at org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet(HibernateTransactionManager.java:356)
at org.springframework.orm.hibernate4.HibernateTransactionManager.<init>(HibernateTransactionManager.java:148)

joined on
November 18,2013
Replied on May 20,2016

There is because hibernate configuration problem. Find sample configuration.

@Configuration 
@EnableTransactionManagement
@PropertySource("classpath:database.properties")
public class DBConfig {
        @Autowired
        private Environment env;
@Bean
public HibernateTemplate hibernateTemplate() {
return new HibernateTemplate(sessionFactory());
}
@Bean
public SessionFactory sessionFactory() {
LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
lsfb.setDataSource(getDataSource());
lsfb.setPackagesToScan("com.concretepage.entity");
lsfb.setHibernateProperties(hibernateProperties());
try {
lsfb.afterPropertiesSet();
} catch (IOException e) {
e.printStackTrace();
}
return lsfb.getObject();
}
@Bean
public DataSource getDataSource() {
   BasicDataSource dataSource = new BasicDataSource();
   dataSource.setDriverClassName(env.getProperty("database.driver"));
   dataSource.setUrl(env.getProperty("database.url"));
   dataSource.setUsername(env.getProperty("database.root"));
   dataSource.setPassword(env.getProperty("database.password"));
   return dataSource;
}
@Bean
public HibernateTransactionManager hibTransMan(){
return new HibernateTransactionManager(sessionFactory());
}
        private Properties hibernateProperties() {
            Properties properties = new Properties();
            properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
            properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
            properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
            return properties;        
       }

Find the link.


Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us