'Why does the setup of a simple project with Maven and Hibernate fail?
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 1:[1]
You might need to add proxy in settings.xml as shown below
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>https</protocol>
<username>abc</</username>
<password>abc123</password>
<host>webproxy.company.com</host>
<port>8081</port>
<!-- <nonProxyHosts>local.net|some.host.com</nonProxyHosts> -->
</proxy>
</proxies>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Swarit Agarwal |
