Problem in configuring Datasource with Postgres!

Asked

Viewed 77 times

0

I am trying to configure my Datasource to create a REST API, the same is not working when using Postgresql, but if using Oracle DB works normally. I would like to use Postgresql, can anyone tell me why of the mistake, what I am doing wrong? I have the following application configuration for Spring Data.

package br.com.controle.empresarial;

import java.util.Properties;

import javax.sql.DataSource;

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
public class DAOConfig {
    @Bean
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setPackagesToScan("br.com.controle.empresarial");
        sessionFactory.setHibernateProperties(hibernateProperties());

        return sessionFactory;
    }

    @Bean
    public DataSource dataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("org.postgresql.Driver");
        dataSource.setUrl("jdbc:postgresql://localhost:5432/");
        dataSource.setUsername("postgres");
        dataSource.setPassword("admin");

        return dataSource;
    }

    @Bean
    public PlatformTransactionManager hibernateTransactionManager() {
        HibernateTransactionManager transactionManager = new HibernateTransactionManager();
        transactionManager.setSessionFactory(sessionFactory().getObject());
        return transactionManager;
    }

    private final Properties hibernateProperties() {
        Properties hibernateProperties = new Properties();
        hibernateProperties.setProperty("hibernate.show_sql", "true");
        hibernateProperties.setProperty("hibernate.format_sql", "true");
        hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
        hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");

        return hibernateProperties;
    }
}

pom.xml pom.xml

Error Erro

Link project -> https://drive.google.com/file/d/1X5tkhnQsK26nlmucFqKjNvaXXAYYbx1Y/view?usp=sharing

  • Hello, post the code in the question and not the print. This does not help the view and also does not allow to copy the code to a possible test.

1 answer

0

Add this to the application.properties file

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Reference

  • I tried to put this already, it didn’t work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.