Skip to content

Commit

Permalink
configuração de dados base
Browse files Browse the repository at this point in the history
Para facilitar o trabalho na aplicação esta sendo utilizado um script sql para inserir os dados necessários
  • Loading branch information
GabryelBoeira committed Oct 9, 2024
1 parent b780b2b commit a3cb070
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
4 changes: 4 additions & 0 deletions VideoLocadora/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@

<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package io.github.gabryel.videolocadora.entity.customer;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
Expand All @@ -11,12 +19,15 @@
@Data
@Entity
@Table(name = "address")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class AddressEntity implements Serializable {

private static final long serialVersionUID = 198873988892602989L;

@Id
private String id;
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String street;

Expand All @@ -34,7 +45,8 @@ public class AddressEntity implements Serializable {

private boolean isBillingAddress;

@ManyToOne
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name = "CUSTOMER_ID", nullable = false)
private CustomerEntity customer;

public AddressEntity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package io.github.gabryel.videolocadora.entity.customer;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
Expand All @@ -12,18 +20,26 @@
@Data
@Entity
@Table(name = "customer")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class CustomerEntity implements Serializable {

private static final long serialVersionUID = 2106833642965188722L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;

private String cpf;

@Column(name = "delay_devolution")
private boolean delayDevolution;

private String email;

@OneToMany
@OneToMany(mappedBy = "customer", cascade= CascadeType.ALL, fetch= FetchType.LAZY)
private List<AddressEntity> addressList;

public CustomerEntity() {}
Expand Down
23 changes: 15 additions & 8 deletions VideoLocadora/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,28 @@ spring:
config:
activate:
on-profile: development

sql.init.mode: always
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/videolocadora
url: jdbc:mysql://localhost:3306/videolocadora?useSSL=false
username: root
password: root

initialization-mode: always
jpa:
show-sql: true
show-sql: false
database: mysql
generate-ddl: false
hibernate.ddl-auto: none
properties:
hibernate:
globally_quoted_identifiers: true
format_sql: true
defer-datasource-initialization: true
hibernate:
ddl-auto: create
globally_quoted_identifiers: true
format_sql: true
dialect : org.hibernate.dialect.MySQL8Dialect
jackson:
serialization:
FAIL_ON_EMPTY_BEANS: false


---
spring:
Expand Down
8 changes: 8 additions & 0 deletions VideoLocadora/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#-- ADD CLIENTES, CPFs gerados automaticamente https://www.4devs.com.br/gerador_de_cpf


insert into CUSTOMER (ID, NAME, CPF, DELAY_DEVOLUTION, EMAIL) values (-2, 'João' , '37772382014', false, 'j@j.com');
insert into CUSTOMER (ID, NAME, CPF, DELAY_DEVOLUTION, EMAIL) values (-3, 'Jose' , '06355528091', false, 'j@j.com');
insert into CUSTOMER (ID, NAME, CPF, DELAY_DEVOLUTION, EMAIL) values (-4, 'Carlos', '80071319069', false, 'j@j.com');
insert into CUSTOMER (ID, NAME, CPF, DELAY_DEVOLUTION, EMAIL) values (-5, 'Pedro' , '81454522011', false, 'j@j.com');
insert into CUSTOMER (ID, NAME, CPF, DELAY_DEVOLUTION, EMAIL) values (-6, 'Will' , '14915748014', false, 'j@j.com');

0 comments on commit a3cb070

Please sign in to comment.