Estou com erro ao tentar conectar em banco de dados PostgreSQL 9.2.6 com Hibernate.
O banco de dados existe e é possível conectar via terminal.
Maven:
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
</dependency>
entityManagerFactory:
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factoryBean =
new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter vendorAdapater = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(vendorAdapater);
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername("postgres");
dataSource.setPassword("postgres");
dataSource.setUrl("jdbc::postgresql//localhost:5432/casadocodigo");
dataSource.setDriverClassName("org.postgresql.Driver");
factoryBean.setDataSource(dataSource);
Properties props = new Properties();
props.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
props.setProperty("hibernate.show_sql", "true");
props.setProperty("hibernate.hbm2ddl.auto", "update");
factoryBean.setJpaProperties(props);
factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models");
return factoryBean;
}
Exceção:
java.sql.SQLException: No suitable driver found for jdbc::postgresql//localhost:5432/casadocodigo
java.sql.DriverManager.getConnection(DriverManager.java:689)
java.sql.DriverManager.getConnection(DriverManager.java:208)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)
org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228)
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171)
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162)
org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1431)
org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:61)