Issue
It is a simple project that consists of making a MySQL query and displaying it. I use NetBeans. The hibernate.xml and client.xml file were created by NetBeans (Hibernate Configuration Wizard and Hibernate Mapping Wizard). I really have no idea what the problem is. 1) POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>alsoMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.10.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
2) Main Class:
public static void main(String[] args) {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // obtiene los valores de hibernate.cfg.xml
.build();
try {
SessionFactory sessionFactory = new MetadataSources(registry)
.buildMetadata().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Cliente c = (Cliente) session.load(Cliente.class, 1);
System.out.println(c);
session.getTransaction().commit();
session.close();
sessionFactory.close();
} catch (Exception e) {
e.printStackTrace();
}
}
3) Exception:
------------------------------------------------------------------------
Building alsoMaven 1.0-SNAPSHOT
------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.1.1.Final/jboss-transaction-api_1.2_spec-1.1.1.Final.jar
Downloading: http://repo.maven.apache.org/maven2/org/javassist/javassist/3.24.0-GA/javassist-3.24.0-GA.jar
Downloading: http://repo.maven.apache.org/maven2/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar
Downloading: http://repo.maven.apache.org/maven2/org/hibernate/common/hibernate-commons-annotations/5.1.0.Final/hibernate-commons-annotations-5.1.0.Final.jar
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.184s
Finished at: Sun Mar 08 21:10:54 GMT-03:00 2020
Final Memory: 6M/16M
------------------------------------------------------------------------
Failed to execute goal on project alsoMaven: Could not resolve dependencies for project com.mycompany:alsoMaven:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.jboss.logging:jboss-logging:jar:3.3.2.Final, org.javassist:javassist:jar:3.24.0-GA, org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.1.1.Final, org.hibernate.common:hibernate-commons-annotations:jar:5.1.0.Final: Could not transfer artifact org.jboss.logging:jboss-logging:jar:3.3.2.Final from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
Thx!
Solution
Starting 15 January 2020, the Maven Central repository doesn't support insecure communication over plain HTTP. You have to adjust your local configuration.
With this in mind, we find an important detail in the error message:
Return code is: 501, ReasonPhrase:HTTPS Required.
As we can see in the output, you are still using plain, un-encrypted connections to query/retrieve artefacts from Maven Central:
Downloading: http://repo.maven.apache.org/maven2/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.1.1.Final/jboss-transaction-api_1.2_spec-1.1.1.Final.jar
...
Make sure that your local settings.xml contains only entries with https for the Maven central repositories in it. Consequently, the entry http://repo.maven.apache.org/maven2/
must be changed into https://repo.maven.apache.org/maven2/
.
A minimal working configuration reads as follows:
<profile>
<id>maven-https</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
Hope it helps.
Answered By - MWiesner
Answer Checked By - Katrina (JavaFixing Volunteer)