EntityManagerException while running in Travis CI, Spring Boot and PostgreSQL

Bogdan Zeleniuk

I made a simple web application using Spring Boot, PostgreSQL, Maven and JUnit. While running it in my IDE (mvn clear-verify) everything works perfect but while running in Travis CI I got this exception:

Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

and a lot of others. My tests run perfect as well in IDE. Can someone tell me why? My code is here:

Entity:

@Entity
@Table(name = "contacts")
public class Contact extends BaseEntity{

    @Column(name = "name", nullable = false)
    private String name;

    public Contact() {
    }
    public Contact(String name) {
        this(null,name);
    }
    public Contact(Integer id, String name) {
        super(id);
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Contact{" +
                "id='" + id + '\'' +
                "name='" + name + '\'' +
                '}';
    }
}

Repository:

@Repository
public class ContactRepositoryImpl implements ContactRepository{

    private static final Logger LOG = LoggerFactory.getLogger(ContactRepositoryImpl.class);

    @Autowired
    private ProxyContactRepository proxyContactRepository;

    private Pattern regexPattern;

    @Override
    public List<Contact> getAllSorted(String nameFilter) {
        List<Contact> listOfAllContacts = new CopyOnWriteArrayList<>();
        try {
            regexPattern = Pattern.compile(nameFilter);
            if (!nameFilter.isEmpty() || nameFilter.length() != 0) {
                listOfAllContacts.addAll(getAll().stream().filter(contact -> notDoMatch(contact.getName())).collect(Collectors.toList()));
            } else {
                LOG.warn("Regex parameter " + "'" + nameFilter + "'" + " is empty");
                throw new NotFoundException("Regex parameter is empty");
            }
            return listOfAllContacts;
        }
        catch (PatternSyntaxException exception){
            LOG.error("Regex parameter " + "'" + nameFilter + "'" + " is invalid");
            throw new NotFoundException("Regex parameter is invalid");
        }
    }

    @Override
    public List<Contact> getAll() {
        return proxyContactRepository.findAll();
    }

    private boolean notDoMatch(String word){
        Matcher matcher = regexPattern.matcher(word);
        return !matcher.matches();
    }
}

Controller:

@RestController
@RequestMapping("/contacts")
public class ContactController extends AbstractContactController{

    @RequestMapping(method = RequestMethod.GET, params = "nameFilter")
    public List<Contact> getSortedPage(@RequestParam("nameFilter") String nameFilter){
        return super.getAllSorted(nameFilter);
    }

    @RequestMapping(method = RequestMethod.GET)
    public List<Contact> getAllPage(){
        return super.getAll();
    }
}

travis.yml

language: java
script: mvn clean verify
jdk: oraclejdk8

services:
- postgresql

before_script:
- psql -c 'create database hello;' -U postgres

And app.properties:

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/hello
spring.datasource.username=postgres
spring.datasource.password=password

spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL81Dialect

enter image description here I checked the connection to PostgreSQL DB and it works (you can see it on picture), but I do not have Entity Manager in Test. Can somebody tell my what is it?

luboskrnac

I would suggest to use H2 for integration testing instead of PostgreSQL. You don't need to setup any TravisCI service. You test suite will be much more maintainable and not dependent on external service. You can also use H2's compatibility mode with PostgreSQL.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Running Redis on Travis CI

From Dev

Spring Boot Application test build fails on Travis CI

From Dev

Exception while running Spring boot cassandra project

From Dev

Compilation error while running a spring boot application

From Dev

Travis-CI running two android emulators

From Dev

Travis-CI running two android emulators

From Dev

Travis CI - Running Command on Job Cancellation

From Dev

Runtime error while running a Spring Session + Spring Boot application

From Dev

Setting up postgresql in Travis CI for django project

From Dev

Which travis CI build images boot the fastest?

From Dev

Launch GWT in dev mode while running server on Spring-boot

From Dev

error while running integration test with spring boot and testng

From Dev

Error while running spring boot tests, SpringRunner.class Not found

From Dev

Invalid syntax while running test on Travis

From Dev

Getting gcc command not found when running the Makefile on travis CI

From Dev

Running tests with API authentication in Travis CI without exposing API passwords

From Dev

Django app failing in Travis CI: server not running on localhost

From Dev

Getting gcc command not found when running the Makefile on travis CI

From Dev

Django app failing in Travis CI: server not running on localhost

From Dev

running sh script on travis CI: The command exited with 1

From Dev

How to test Pl/Python PostgreSQL procedures with Travis CI?

From Dev

How to set up Django to run tests on PostgreSQL on Travis CI?

From Dev

How to test Pl/Python PostgreSQL procedures with Travis CI?

From Dev

Postgresql database doesn't exist in travis ci after being created

From Dev

Running tests with Spring Boot

From Dev

Scheduler not running in Spring Boot

From Dev

Running spring boot on server

From Dev

Travis CI build fails for PHP 5.4 while trying to run composer

From Dev

Getting NoSuchMethodError: javax.servlet.ServletContext.addServlet in Spring Boot while running a Spring MVC application

Related Related

  1. 1

    Running Redis on Travis CI

  2. 2

    Spring Boot Application test build fails on Travis CI

  3. 3

    Exception while running Spring boot cassandra project

  4. 4

    Compilation error while running a spring boot application

  5. 5

    Travis-CI running two android emulators

  6. 6

    Travis-CI running two android emulators

  7. 7

    Travis CI - Running Command on Job Cancellation

  8. 8

    Runtime error while running a Spring Session + Spring Boot application

  9. 9

    Setting up postgresql in Travis CI for django project

  10. 10

    Which travis CI build images boot the fastest?

  11. 11

    Launch GWT in dev mode while running server on Spring-boot

  12. 12

    error while running integration test with spring boot and testng

  13. 13

    Error while running spring boot tests, SpringRunner.class Not found

  14. 14

    Invalid syntax while running test on Travis

  15. 15

    Getting gcc command not found when running the Makefile on travis CI

  16. 16

    Running tests with API authentication in Travis CI without exposing API passwords

  17. 17

    Django app failing in Travis CI: server not running on localhost

  18. 18

    Getting gcc command not found when running the Makefile on travis CI

  19. 19

    Django app failing in Travis CI: server not running on localhost

  20. 20

    running sh script on travis CI: The command exited with 1

  21. 21

    How to test Pl/Python PostgreSQL procedures with Travis CI?

  22. 22

    How to set up Django to run tests on PostgreSQL on Travis CI?

  23. 23

    How to test Pl/Python PostgreSQL procedures with Travis CI?

  24. 24

    Postgresql database doesn't exist in travis ci after being created

  25. 25

    Running tests with Spring Boot

  26. 26

    Scheduler not running in Spring Boot

  27. 27

    Running spring boot on server

  28. 28

    Travis CI build fails for PHP 5.4 while trying to run composer

  29. 29

    Getting NoSuchMethodError: javax.servlet.ServletContext.addServlet in Spring Boot while running a Spring MVC application

HotTag

Archive