Hello,
I’m using the Hibernate framework along with Maven in IntelliJ. I’m creating a MySQL database, I also have some ORM classes that map the MySQL database, and then I’m running some JUNIT tests to make sure everything works.
Where I’m having trouble is in two places, which are related to each other:
- When I run
mvn test
, sometimes my JUNIT tests work fine and are able to query the simulated database, establish a connection (even though it’s just with the simulated database), execute a statement, etc. However, sometimes, if I runmvn clean
before runningmvn test
, while the JUNIT tests still execute, the tests output with failures (not errors, just failures, thought this is still bad, of course). - The problem outlined in #1 is essentially duplicated when I upload to GitHub and run CircleCI (which isn’t surprising, since CircleCI runs
mvn test
when doing its integration testing). Most of my uploads failed, but one of them finally worked. However, I’m not exactly sure why the “final” upload was successful while the others weren’t.
The error messages I’m getting either from mvn test
or the CircleCI builds are typically as follows. These errors are from my pent-ultimate upload, the one I did just prior to the next upload which actually worked:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
com.mysql.cj.exceptions.CJException: Public Key Retrieval is not allowed
java.sql.SQLNonTransientConnectionException: Could not create connection to database server
I should also note that my intention is to run mvn clean
first, then upload to CircleCI, however, running mvn clean
seems to be somehow involved in perpetuating these errors.
As far as different resources I’m using go, here they are. If I’m forgetting something, please let me know and I should be able to include it.
In my hibernate.cfg.xml file, I have the following lines:
<property name="connection.url">jdbc:mysql://localhost:3306/stocks</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
At the end of the word “stocks” on the first line, I have sometimes appended any of the following (sometimes I only appended one of the following, other times I combined them, depending on the error(s) from either Maven or CircleCI). Appending some combination of these lines seemed to help get things to work, but running mvn clean
seemed to halt any effect these additions were
autoReconnect=true
useSSL=false
allowPublicKeyRetrieval=true
Running the JUNIT tests from within IntelliJ usually works, but if I run mvn clean
first, then IntelliJ usually won’t work, unless I then go back into this file and append ?autoReconnect=true&useSSL=false
. If I do that, then IntelliJ will run the JUNIT tests fine.
In my config.yml file for CircleCI, I have the following code. Certain statements were added in MAVEN_OPTS based on other research I did to try to counteract the errors I was getting, but I don’t know if these statements are having any impact one way or the other:
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
- image: circleci/mysql:latest-ram
environment:
- MYSQL_ROOT_PASSWORD: (my real password goes here)
- MYSQL_DATABASE: stocks
- MYSQL_USER: bob
- MYSQL_PASSWORD: (the real password goes here)
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true
steps:
- checkout
- run: sudo apt install -y mysql-client
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
# run tests!
- run: mvn integration-test
If anyone has any idea what’s going on, I appreciate the help. My goal is to be able to upload to CircleCI by first running mvn clean
so only the src
files, pom.xml
file, and .circleci
folder are included in the upload. Also, not to belabor the point, but my most recent upload to CircleCI did in fact work, but I’m not sure what made that build work while all the others ones did not.
I’ve looked all over for an answer, but I’m suspecting that part of the problem is that I’m not necessarily asking the right questions (probably because I can’t seem to figure out what the underlying issue is, which would help identify the correct questions, which would…you get the idea).
Thanks for any help,
James