Spring jpa entity and Lombok

Cawa

I've created project with spring.

dependencies {
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-devtools')
    compile('org.projectlombok:lombok')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.codehaus.groovy:groovy')
    runtime('com.h2database:h2')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}

application.properties:

spring.data.rest.base-path=/api

spring.datasource.url=jdbc:mysql://localhost/secret_backend
spring.datasource.username=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

And the entity class:

package com.app.Entity

import lombok.Data

import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Table

@Data
@Entity
@Table(name = "cities")
public class City {

    private @Id @GeneratedValue Long id;
    private String slug;
    private String title;
    private String titleShort;

    private City() {}

    /*public String getSlug(){
        return slug;
    }*/

    public City(String slug) {
        this.slug = slug;
    }
}

When I'm navigating to localhost:8080/api/cities, I don't see actual data form database:

{
  "_embedded": {
    "cities": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/cities/7"
          },
          "city": {
            "href": "http://localhost:8080/api/cities/7"
          }
        }
      },
      {
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/cities/8"
          },
          "city": {
            "href": "http://localhost:8080/api/cities/8"
          }
        }
      },
...

Only if I'm adding getters to entity I see the data, but from lombok documentation @Data annotation must generate getters and setters for all entity properties.

Cawa

Renamed City.groovy to City.java, and now it working fine. Thanks to @highstakes

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Spring jpa entity and Lombok

分類Dev

Spring jpa entity and Lombok

分類Dev

Spring JPA - RESTful partial update and validation for entity

分類Dev

A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance - Spring and Lombok

分類Dev

Spring JPAの@Entityとは何ですか?

分類Dev

JPA / Spring / Delete Entity、type Mismatch(int / long for id)

分類Dev

Spring JPA Specification to filter one to many relation with child entity

分類Dev

JPA entity mapping

分類Dev

Spring, Hibernate, JPA - Why am i not using entity manager, why does casacdeType.Persist only work with entity manager

分類Dev

SpringステートマシンのJpaRepositoryStateとJPAの@Entity

分類Dev

Spring Data JPA map the stored procedure result to Non-Entity POJO from multiple data source

分類Dev

Spring BootでLombokを使用してJPAエンティティのBuilder()にアクセスする方法は?

分類Dev

JPA: Search for an associated entity in an entity hierarchy

分類Dev

Spring + Lombok: Can I have @Autowired @Setter

分類Dev

Mapstruct + Lombok with Gradle in Spring Boot(Bean Not Found)

分類Dev

JPA @Entityの継承

分類Dev

JPA対Spring JdbcTemplate

分類Dev

Spring + Hibernate + JPA

分類Dev

Spring JPAの代替

分類Dev

Spring JPA Criar perguntas

分類Dev

Spring Boot jpa NoClassDefFoundError

分類Dev

Spring Boot JPA findByUuid

分類Dev

Java Spring JPA insert into

分類Dev

Spring JPA Multiple Datasources

分類Dev

Spring Data JPA @OneToMany

分類Dev

String as Id for Spring entity

分類Dev

Spring Boot + Spring Batch + Spring JPA

分類Dev

Extending a lombok annotation using Spring's meta-annotations

分類Dev

Unable to save Entity with OneToMany mapping using JPA

Related 関連記事

  1. 1

    Spring jpa entity and Lombok

  2. 2

    Spring jpa entity and Lombok

  3. 3

    Spring JPA - RESTful partial update and validation for entity

  4. 4

    A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance - Spring and Lombok

  5. 5

    Spring JPAの@Entityとは何ですか?

  6. 6

    JPA / Spring / Delete Entity、type Mismatch(int / long for id)

  7. 7

    Spring JPA Specification to filter one to many relation with child entity

  8. 8

    JPA entity mapping

  9. 9

    Spring, Hibernate, JPA - Why am i not using entity manager, why does casacdeType.Persist only work with entity manager

  10. 10

    SpringステートマシンのJpaRepositoryStateとJPAの@Entity

  11. 11

    Spring Data JPA map the stored procedure result to Non-Entity POJO from multiple data source

  12. 12

    Spring BootでLombokを使用してJPAエンティティのBuilder()にアクセスする方法は?

  13. 13

    JPA: Search for an associated entity in an entity hierarchy

  14. 14

    Spring + Lombok: Can I have @Autowired @Setter

  15. 15

    Mapstruct + Lombok with Gradle in Spring Boot(Bean Not Found)

  16. 16

    JPA @Entityの継承

  17. 17

    JPA対Spring JdbcTemplate

  18. 18

    Spring + Hibernate + JPA

  19. 19

    Spring JPAの代替

  20. 20

    Spring JPA Criar perguntas

  21. 21

    Spring Boot jpa NoClassDefFoundError

  22. 22

    Spring Boot JPA findByUuid

  23. 23

    Java Spring JPA insert into

  24. 24

    Spring JPA Multiple Datasources

  25. 25

    Spring Data JPA @OneToMany

  26. 26

    String as Id for Spring entity

  27. 27

    Spring Boot + Spring Batch + Spring JPA

  28. 28

    Extending a lombok annotation using Spring's meta-annotations

  29. 29

    Unable to save Entity with OneToMany mapping using JPA

ホットタグ

アーカイブ