Skip to content

Commit

Permalink
fix: JPA Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
bohub12 committed Sep 10, 2023
1 parent e3aba4d commit d863777
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.example.demo;

import com.example.demo.member.Member;
import com.example.demo.member.MemberRepository;
import com.example.demo.member.MemberRole;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@SpringBootApplication
public class DemoApplication {
Expand All @@ -10,4 +16,15 @@ public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

@Bean
public CommandLineRunner runner(MemberRepository repository) {
return args -> {
repository.save(new Member(1L, "member1", MemberRole.NORMAL, 10));
repository.save(new Member(2L, "member2", MemberRole.NORMAL, 20));
repository.save(new Member(3L, "member3", MemberRole.NORMAL, 30));
repository.save(new Member(4L, "member4", MemberRole.ADMIN, 40));
repository.save(new Member(5L, "member5", MemberRole.ADMIN, 50));
};
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.demo.member;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -17,6 +14,8 @@ public class Member {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;

@Enumerated(value = EnumType.STRING)
private MemberRole role;
private int age;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.demo.member;


public enum MemberRole {
NORMAL, ADMIN;
}
13 changes: 12 additions & 1 deletion spring-for-graphql/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ spring:
enabled: true
schema:
printer:
enabled: true
enabled: true
h2:
console:
path: "/h2-console"
enabled: true
datasource:
url: "jdbc:h2:mem:testDB"
username: bo
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create

0 comments on commit d863777

Please sign in to comment.