Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 214831e

Browse files
committed
spring-jpa: copied hibernate project structure
1 parent ca8b5f5 commit 214831e

File tree

8 files changed

+424
-0
lines changed

8 files changed

+424
-0
lines changed

spring/spring-data-jpa/app/pom.xml

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>es.msanchez.frameworks.java.spring</groupId>
4+
<artifactId>java-frameworks-spring-data-jpa</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
7+
<properties>
8+
<!-- General -->
9+
<java.compiler.version>1.8</java.compiler.version>
10+
11+
<!-- maven plugins -->
12+
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
13+
<maven.shade.version>3.2.1</maven.shade.version>
14+
15+
<!-- Normal Dependency Versions -->
16+
<hibernate.core.version>5.4.3.Final</hibernate.core.version>
17+
<hibernate.mysql.connector>8.0.16</hibernate.mysql.connector>
18+
19+
<spring.version>5.1.6.RELEASE</spring.version>
20+
<spring-boot.version>2.0.0.RELEASE</spring-boot.version>
21+
22+
<lombok.version>1.18.6</lombok.version>
23+
<slf4j.version>1.7.25</slf4j.version>
24+
<logback.version>1.2.3</logback.version>
25+
<google.guava.version>27.1-jre</google.guava.version>
26+
<apache.commons.collections.version>4.3</apache.commons.collections.version>
27+
28+
<!-- Test Dependency Versions -->
29+
<junit.version>4.12</junit.version>
30+
<testng.version>6.14.3</testng.version>
31+
<mockito.version>2.26.0</mockito.version>
32+
<assertj.version>3.12.2</assertj.version>
33+
<codearte.catchexception.version>1.4.6</codearte.catchexception.version>
34+
35+
</properties>
36+
37+
<dependencies>
38+
39+
<!-- Hibernate -->
40+
<dependency>
41+
<groupId>org.hibernate</groupId>
42+
<artifactId>hibernate-core</artifactId>
43+
<version>${hibernate.core.version}</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>mysql</groupId>
48+
<artifactId>mysql-connector-java</artifactId>
49+
<version>${hibernate.mysql.connector}</version>
50+
</dependency>
51+
52+
53+
<!-- Spring Boot -->
54+
<dependency>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-starter</artifactId>
57+
<version>${spring-boot.version}</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-web</artifactId>
63+
<version>${spring-boot.version}</version>
64+
</dependency>
65+
66+
<!-- Spring -->
67+
<dependency>
68+
<groupId>org.springframework</groupId>
69+
<artifactId>spring-context</artifactId>
70+
<version>${spring.version}</version>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.springframework</groupId>
75+
<artifactId>spring-core</artifactId>
76+
<version>${spring.version}</version>
77+
</dependency>
78+
79+
<!-- Logging -->
80+
<dependency>
81+
<groupId>org.slf4j</groupId>
82+
<artifactId>slf4j-api</artifactId>
83+
<version>${slf4j.version}</version>
84+
</dependency>
85+
86+
<dependency>
87+
<groupId>ch.qos.logback</groupId>
88+
<artifactId>logback-classic</artifactId>
89+
<version>${logback.version}</version>
90+
</dependency>
91+
92+
<dependency>
93+
<groupId>ch.qos.logback</groupId>
94+
<artifactId>logback-core</artifactId>
95+
<version>${logback.version}</version>
96+
</dependency>
97+
98+
<!-- Other dependencies -->
99+
<dependency>
100+
<groupId>org.projectlombok</groupId>
101+
<artifactId>lombok</artifactId>
102+
<version>${lombok.version}</version>
103+
<scope>provided</scope>
104+
</dependency>
105+
106+
<dependency>
107+
<groupId>com.google.guava</groupId>
108+
<artifactId>guava</artifactId>
109+
<version>${google.guava.version}</version>
110+
</dependency>
111+
112+
<dependency>
113+
<groupId>org.apache.commons</groupId>
114+
<artifactId>commons-collections4</artifactId>
115+
<version>${apache.commons.collections.version}</version>
116+
</dependency>
117+
118+
<!-- Test Dependencies -->
119+
<dependency>
120+
<groupId>junit</groupId>
121+
<artifactId>junit</artifactId>
122+
<version>${junit.version}</version>
123+
<scope>test</scope>
124+
</dependency>
125+
126+
<dependency>
127+
<groupId>org.testng</groupId>
128+
<artifactId>testng</artifactId>
129+
<version>${testng.version}</version>
130+
<scope>test</scope>
131+
</dependency>
132+
133+
<dependency>
134+
<groupId>org.mockito</groupId>
135+
<artifactId>mockito-core</artifactId>
136+
<version>${mockito.version}</version>
137+
<scope>test</scope>
138+
</dependency>
139+
140+
<dependency>
141+
<groupId>org.assertj</groupId>
142+
<artifactId>assertj-core</artifactId>
143+
<version>${assertj.version}</version>
144+
<scope>test</scope>
145+
</dependency>
146+
147+
<dependency>
148+
<groupId>eu.codearte.catch-exception</groupId>
149+
<artifactId>catch-exception</artifactId>
150+
<version>${codearte.catchexception.version}</version>
151+
<scope>test</scope>
152+
</dependency>
153+
154+
<!-- Spring test -->
155+
<dependency>
156+
<groupId>org.springframework</groupId>
157+
<artifactId>spring-test</artifactId>
158+
<version>${spring.version}</version>
159+
<scope>test</scope>
160+
</dependency>
161+
162+
<dependency>
163+
<groupId>org.springframework.boot</groupId>
164+
<artifactId>spring-boot-starter-test</artifactId>
165+
<version>${spring-boot.version}</version>
166+
<scope>test</scope>
167+
</dependency>
168+
169+
</dependencies>
170+
171+
<build>
172+
<plugins>
173+
<!-- Solves Manifest not found trouble -->
174+
<plugin>
175+
<groupId>org.springframework.boot</groupId>
176+
<artifactId>spring-boot-maven-plugin</artifactId>
177+
<version>${spring-boot.version}</version>
178+
<executions>
179+
<execution>
180+
<goals>
181+
<goal>repackage</goal>
182+
</goals>
183+
</execution>
184+
</executions>
185+
</plugin>
186+
187+
<!-- Sets the compiler version -->
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-compiler-plugin</artifactId>
191+
<version>${maven.compiler.plugin.version}</version>
192+
<configuration>
193+
<source>${java.compiler.version}</source>
194+
<target>${java.compiler.version}</target>
195+
</configuration>
196+
</plugin>
197+
</plugins>
198+
</build>
199+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package es.msanchez.frameworks.java.spring.boot;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import org.springframework.boot.CommandLineRunner;
7+
import org.springframework.boot.SpringApplication;
8+
import org.springframework.boot.autoconfigure.SpringBootApplication;
9+
import org.springframework.context.ApplicationContext;
10+
import org.springframework.context.annotation.Bean;
11+
12+
import lombok.extern.slf4j.Slf4j;
13+
14+
@Slf4j
15+
@SpringBootApplication
16+
public class Application {
17+
18+
public static void main(final String[] args) {
19+
SpringApplication.run(Application.class, args);
20+
}
21+
22+
@Bean
23+
public CommandLineRunner commandLineRunner(final ApplicationContext context) {
24+
return args -> {
25+
log.info("Beans provided by Spring Boot:");
26+
final List<String> beanNames = Arrays.asList(context.getBeanDefinitionNames());
27+
beanNames.forEach(bean -> log.debug("Bean name '{}'", bean));
28+
};
29+
30+
}
31+
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package es.msanchez.frameworks.java.spring.boot.entity;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.Table;
11+
12+
@Entity
13+
@Table
14+
@Data
15+
@NoArgsConstructor
16+
public class Hobby {
17+
18+
@Id
19+
@GeneratedValue(strategy = GenerationType.IDENTITY)
20+
private Long id;
21+
22+
private String name;
23+
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package es.msanchez.frameworks.java.spring.boot.entity;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
6+
import javax.persistence.CascadeType;
7+
import javax.persistence.Entity;
8+
import javax.persistence.GeneratedValue;
9+
import javax.persistence.GenerationType;
10+
import javax.persistence.Id;
11+
import javax.persistence.ManyToMany;
12+
import javax.persistence.Table;
13+
import java.util.List;
14+
15+
@Table
16+
@Entity
17+
@Data
18+
@NoArgsConstructor
19+
public class Person {
20+
21+
@Id
22+
@GeneratedValue(strategy = GenerationType.IDENTITY)
23+
private Long id;
24+
25+
private String name;
26+
27+
private Integer age;
28+
29+
@ManyToMany(cascade = CascadeType.PERSIST)
30+
private List<Hobby> hobbies;
31+
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package es.msanchez.frameworks.java.spring.boot.hibernate;
2+
3+
import lombok.Getter;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.hibernate.SessionFactory;
6+
import org.hibernate.cfg.Configuration;
7+
8+
@Slf4j
9+
public class HibernateUtil {
10+
11+
@Getter
12+
private static final SessionFactory SESSION_FACTORY = HibernateUtil.buildSessionFactory();
13+
14+
private static SessionFactory buildSessionFactory() {
15+
try {
16+
return new Configuration().configure().buildSessionFactory();
17+
} catch(final Throwable ex) {
18+
log.error("Failure on ini hibernate session. ", ex);
19+
throw new ExceptionInInitializerError(ex);
20+
}
21+
}
22+
23+
public static void shutdown() {
24+
SESSION_FACTORY.close();
25+
}
26+
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE hibernate-configuration PUBLIC
3+
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
4+
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
5+
<hibernate-configuration>
6+
<session-factory>
7+
8+
<property name="connection.url">jdbc:mysql://localhost:3310/hibernate</property>
9+
<property name="connection.username">hibernate_user</property>
10+
<property name="connection.password">hibernate_pass</property>
11+
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
12+
<property name="dialect">org.hibernate.dialect.MySQL8Dialect</property>
13+
14+
<property name="show_sql">true</property>
15+
<property name="format_sql">true</property>
16+
<property name="hibernate.hbm2ddl.auto">update</property>
17+
18+
<!-- JDBC connection pool (use the built-in) -->
19+
<property name="connection.pool_size">100</property>
20+
<property name="current_session_context_class">thread</property>
21+
22+
<mapping class="es.msanchez.frameworks.java.spring.boot.entity.Person"/>
23+
<mapping class="es.msanchez.frameworks.java.spring.boot.entity.Hobby"/>
24+
25+
</session-factory>
26+
</hibernate-configuration>

0 commit comments

Comments
 (0)