-2
Good morning, you guys! Can anyone help me? I’m a beginner, and I’m starting to do a Maven project, I’m trying to run the project and this giving error:
**INFO: HHH000400: Using dialect: org.hibernate.dialect.Mysqldialect Session factory cannot be created -> java.lang.Noclassdeffounderror: javax/validation/Validatorfactory Exception in thread "main" java.lang.Exceptionininitializererror at br.com.asdb.util.Hibernateutil.(Hibernateutil.java:25) At Testehibernate.main(Testehibernate.java:9) Caused by: java.lang.Noclassdeffounderror: javax/validation/Validatorfactory at java.base/java.lang.Class.getDeclaredMethods0(Native Method) at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3334) at java.base/java.lang.Class.getMethodsRecursive(Class.java:3475) at java.base/java.lang.Class.getMethod0(Class.java:3461) at java.base/java.lang.Class.getMethod(Class.java:2193) at org.hibernate.cfg.beanvalidation.Beanvalidationintegrator.Integrate(Beanvalidationintegrator.java:113) at org.hibernate.Internal.SessionFactoryImpl.(Sessionfactoryimpl.java:292) at org.hibernate.boot.internal.Sessionfactorybuilderimpl.build(Sessionfactorybuilderimpl.java:471) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:728) at br.com.asdb.util.Hibernateutil.(Hibernateutil.java:21) ... 1 more Caused by: java.lang.Classnotfoundexception: javax.validation.Validatorfactory java.base/jdk.internal.Loader.BuiltinClassLoader.loadClass(Builtinclassloader.java:636) at java.base/jdk.internal.Classloaders$Appclassloader.loadClass(Classloaders.java:182) at java.base/java.lang.Classloader.loadClass(Classloader.java:519) ... 11 more
The pom.xml file ****
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/drogaria
</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">10111978</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">180</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<mapping class="br.com.asdb.entidades.Pessoa" />
</session-factory>
**
The class Hibernateutil: ****package br.com.asdb.util;
import org.hibernate.Session; import org.hibernate.Sessionfactory; import org.hibernate.boot.registry.Standardserviceregistrybuilder; import org.hibernate.cfg.Configuration; import org.hibernate.service.Serviceregistry;
public class Hibernateutil {
private static final SessionFactory fabricaDeSessoes;
static {
try {
Configuration configuracao = new Configuration();
configuracao.configure();
ServiceRegistry registroServico = new StandardServiceRegistryBuilder()
.applySettings(configuracao.getProperties()).build();
fabricaDeSessoes = configuracao.buildSessionFactory(registroServico);
}
catch(Throwable ex) {
System.err.println("A fábrica de sessões não pode ser criada -> " + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() {
return fabricaDeSessoes.openSession();
}
}**
And this is the file Hibernate.cfg.xml ****
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/drogaria</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">10111978</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">180</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<mapping class="br.com.asdb.entidades.Pessoa" />
</session-factory>
**
Classe Pessoa ****package br.com.asdb.entities;
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Generatedvalue; import javax.persistence.Id; import javax.persistence.Table;
@Entity @Table(name="person") public class Pessoa { Private Long code; private string name;
@Id
@GeneratedValue
public Long getCodigo() {
return codigo;
}
public void setCodigo(Long codigo) {
this.codigo = codigo;
}
@Column(name="nome")
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
} **