Answer the question
In order to leave comments, you need to log in
How to properly connect JAXB for Hibernate?
Hello, I can’t build a Maven project using hibernate
, here is my pom.xml : there are only 2 dependencies added third-party ones in the hope that this will help, but no
<?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>firstCRUDapp</groupId>
<artifactId>firstCRUDapp</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5.jre7</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.18.Final</version>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
public class HibernateSessionFactoryUtil {
private static SessionFactory sessionFactory;
private HibernateSessionFactoryUtil() {}
public static SessionFactory getSessionFactory() {
if(sessionFactory == null) {
try {
Configuration configuration = new Configuration().configure(); //ошибка здесь
configuration.addAnnotatedClass(User.class);
configuration.addAnnotatedClass(Auto.class);
//???????
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(builder.build());
}catch (Exception ex){
ex.printStackTrace();
}
}
return sessionFactory;
}
}
Answer the question
In order to leave comments, you need to log in
The exception occurs due to the fact that Hibernate needs JAXB, and in Java9 it was moved to a separate model. You can try adding it to pom.xml as an explicit dependency. If it does not help, you will have to deal with modularity ( one , two ) and how to connect modules in IDEA .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question