Setup Hibernate for DB Nodes + PostgreSQL
This commit is contained in:
@@ -15,6 +15,35 @@
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>6.6.3.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.persistence</groupId>
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.7.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.24.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.24.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.github.lumijiez;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
|
||||
public class Data {
|
||||
private static final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
static {
|
||||
entityManagerFactory = Persistence.createEntityManagerFactory("mainUnit");
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
return entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
|
||||
entityManagerFactory.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
package io.github.lumijiez;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Node up");
|
||||
EntityManager em = Data.getEntityManager();
|
||||
|
||||
System.out.println("Connected to DB << symphony >>");
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.github.lumijiez;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="users")
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
public User() {}
|
||||
|
||||
public User(Long id, String name, String email) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence
|
||||
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
||||
version="3.0">
|
||||
<persistence-unit name="mainUnit" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<class>io.github.lumijiez.User</class>
|
||||
|
||||
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
||||
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver" />
|
||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://postgres_db:5432/symphony" />
|
||||
<property name="jakarta.persistence.jdbc.user" value="symphony" />
|
||||
<property name="jakarta.persistence.jdbc.password" value="symphony" />
|
||||
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
|
||||
|
||||
<property name="hibernate.c3p0.min_size" value="5"/>
|
||||
<property name="hibernate.c3p0.max_size" value="20"/>
|
||||
<property name="hibernate.c3p0.timeout" value="300"/>
|
||||
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
|
||||
<property name="hibernate.c3p0.max_statements" value="50"/>
|
||||
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
<property name="hibernate.format_sql" value="true" />
|
||||
|
||||
<property name="hibernate.hbm2ddl.auto" value="update" />
|
||||
|
||||
<property name="hibernate.cache.use_second_level_cache" value="false" />
|
||||
|
||||
<property name="hibernate.current_session_context_class" value="thread" />
|
||||
|
||||
<property name="hibernate.generate_statistics" value="true" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
Reference in New Issue
Block a user