Skip to content

Commit 9bcd621

Browse files
Merge pull request #1 from DouglasEleuterio/MySQL-DEMO
Changed for MySQL
2 parents 550efb2 + 3c2486d commit 9bcd621

File tree

4 files changed

+67
-64
lines changed

4 files changed

+67
-64
lines changed

pom.xml

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
6-
<groupId>com.example</groupId>
7-
<artifactId>postgres-demo</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
<packaging>jar</packaging>
10-
11-
<name>postgres-demo</name>
12-
<description>Demo project for Spring Boot</description>
13-
14-
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.2.1.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
19-
</parent>
20-
21-
<properties>
22-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
25-
</properties>
26-
27-
<dependencies>
28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-data-jpa</artifactId>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.springframework.boot</groupId>
34-
<artifactId>spring-boot-starter-web</artifactId>
35-
</dependency>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>postgres-demo</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>postgres-demo</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.2.1.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-data-jpa</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
3636

3737
<dependency>
38-
<groupId>org.postgresql</groupId>
39-
<artifactId>postgresql</artifactId>
40-
<scope>runtime</scope>
38+
<groupId>mysql</groupId>
39+
<artifactId>mysql-connector-java</artifactId>
4140
</dependency>
4241
<dependency>
4342
<groupId>org.springframework.boot</groupId>
@@ -46,14 +45,14 @@
4645
</dependency>
4746
</dependencies>
4847

49-
<build>
50-
<plugins>
51-
<plugin>
52-
<groupId>org.springframework.boot</groupId>
53-
<artifactId>spring-boot-maven-plugin</artifactId>
54-
</plugin>
55-
</plugins>
56-
</build>
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
</plugin>
54+
</plugins>
55+
</build>
5756

5857

5958
</project>

src/main/java/com/example/postgresdemo/model/Answer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import org.hibernate.annotations.OnDeleteAction;
66

77
import javax.persistence.*;
8+
import java.io.Serializable;
89

910
@Entity
1011
@Table(name = "answers")
11-
public class Answer extends AuditModel {
12+
public class Answer extends AuditModel implements Serializable {
13+
14+
private static final long servialVersionUID = 1L;
15+
1216
@Id
13-
@GeneratedValue(generator = "answer_generator")
14-
@SequenceGenerator(
15-
name = "answer_generator",
16-
sequenceName = "answer_sequence",
17-
initialValue = 1000
18-
)
17+
@GeneratedValue(strategy = GenerationType.IDENTITY)
18+
1919
private Long id;
2020

2121
@Column(columnDefinition = "text")

src/main/java/com/example/postgresdemo/model/Question.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
import javax.persistence.*;
44
import javax.validation.constraints.NotBlank;
55
import javax.validation.constraints.Size;
6+
import java.io.Serializable;
67

78
@Entity
89
@Table(name = "questions")
9-
public class Question extends AuditModel {
10+
public class Question extends AuditModel implements Serializable {
11+
private static final long servialVersionUID = 1L;
12+
1013
@Id
11-
@GeneratedValue(generator = "question_generator")
12-
@SequenceGenerator(
13-
name = "question_generator",
14-
sequenceName = "question_sequence",
15-
initialValue = 1000
16-
)
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
1715
private Long id;
1816

1917
@NotBlank
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
2-
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres_demo
3-
spring.datasource.username= postgres
4-
spring.datasource.password=
1+
#Trabalhando com MySQL
2+
spring.datasource.url=jdbc:mysql://localhost:3306/demo?useTimezone=true&serverTimezone=UTC&useSSL=false
3+
spring.datasource.username=root
4+
spring.datasource.password=root
55

66
# The SQL dialect makes Hibernate generate better SQL for the chosen database
7-
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
7+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
88

99
# Hibernate ddl auto (create, create-drop, validate, update)
10-
spring.jpa.hibernate.ddl-auto = update
10+
spring.jpa.hibernate.ddl-auto=update
11+
spring.jpa.show-sql=true
12+
spring.jpa.properties.hibernate.format_sql=true
13+
14+
spring.datasource.hikari.maximum-pool-size=25
15+
16+

0 commit comments

Comments
 (0)