Я использую Hibernate и PostgresSQL и пытаюсь создать таблицу в формате .xml, но безуспешно.
Я не вижу ошибки при запуске Main.class. Может мне стоит использовать другую версию Hibernate?
Я использую Gradle и добавил зависимости для последних версий hibernate-core, hibernate-entitymanager и hibernate-validator.
Я смотрел видео, опубликованное в 2016 году: возможно, в этом есть проблема.
Hibernate cfg:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="connection.username">pavel</property>
<property name="connection.password">31228900</property>
<property name="connection.pool_size">10</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="planetofUsers.cfg.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="hibernateLesson.Planet" table="planet">
<id name="id" >
<generator class="native" />
</id>
<property name="age" column="age" type="int" />
<property name="firstName" column="first_name" type="string" />
<property name="lastName" column="last_name" type="string" />
</class>
</hibernate-mapping>
Классы Java:
import lombok.Data;
import lombok.experimental.FieldDefaults;
import static lombok.AccessLevel.PRIVATE;
@Data
@FieldDefaults(level = PRIVATE)
public class Planet {
long id;
int age;
String firstName;
String
import lombok.experimental.FieldDefaults;
import org.hibernate.SessionFactory;
import static lombok.AccessLevel.PRIVATE;
public class Main {
public static void main(String[] args) {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
}
}
package hibernateLesson;
import lombok.experimental.FieldDefaults;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import static lombok.AccessLevel.PRIVATE;
@FieldDefaults(level = PRIVATE)
public class HibernateUtil {
static SessionFactory sessionFactory = null;
static {
Configuration cfg = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties());
sessionFactory = cfg.buildSessionFactory(builder.build());
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}