Fibinger Ádám
2019-02-26 a3ad9416244f132e9fad22b06911ec277615d3d5
H2 basics with JPA
3 files added
2 files modified
51 ■■■■■ changed files
pom.xml 20 ●●●● patch | view | raw | blame | history
src/main/java/hu/unr/fiber/cardapi/Card.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/hu/unr/fiber/cardapi/CardRepository.java 6 ●●●●● patch | view | raw | blame | history
src/main/resources/application.properties 10 ●●●●● patch | view | raw | blame | history
src/main/resources/data.sql 4 ●●●● patch | view | raw | blame | history
pom.xml
@@ -16,16 +16,26 @@
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
src/main/java/hu/unr/fiber/cardapi/Card.java
@@ -1,15 +1,26 @@
package hu.unr.fiber.cardapi;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Objects;
@Entity
public class Card {
    public static final long INVALID_ID = 0;
    @Id
    @GeneratedValue
    private long id = INVALID_ID;
    private String name;
    //FIXME: @Pattern([0-9]+)
    private String number;
    private String cardHolder;
    public Card(){
        super();
    }
    public Card(long id) {
        this.id = id;
    }
src/main/java/hu/unr/fiber/cardapi/CardRepository.java
New file
@@ -0,0 +1,6 @@
package hu.unr.fiber.cardapi;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CardRepository extends JpaRepository<Card, Long> {
}
src/main/resources/application.properties
New file
@@ -0,0 +1,10 @@
# Enabling H2 Console
spring.h2.console.enabled=true
#Turn Statistics on
spring.jpa.properties.hibernate.generate_statistics=true
logging.level.org.hibernate.stat=debug
# Show all queries
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.type=trace
src/main/resources/data.sql
New file
@@ -0,0 +1,4 @@
INSERT INTO CARD(ID, NAME, NUMBER) values(1,'Első kártya', '1')
INSERT INTO CARD(ID, NAME, NUMBER) values(2,'Második kártya', '2')
INSERT INTO CARD(ID, NAME, NUMBER) values(3,'Harmadik kártya', '4')
INSERT INTO CARD(ID, NAME, NUMBER) values(10,'Tízezer egyszázadik kártya', '10100')