0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Spring Bootでエンティティクラスに@Dataが使用できない場合

Last updated at Posted at 2025-03-17

個人開発でSpring Bootを使用して@Dataが使用できない場面に遭遇

個人開発で簡単なCRUD機能を持つAPIを作成していたのですが、
JPAのエンティティクラスで@Dataアノテーションが使用できない(使用しないほうがいい)問題に遭遇したので記しておきます。

修正前

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name="booksinfo")
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    private int id;

    @Column(name="title")
    private String title;

    @Column(name="price")
    private Integer price;

}

修正後

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Table(name="booksinfo")
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    private int id;

    @Column(name="title")
    private String title;

    @Column(name="price")
    private Integer price;

}

主な理由は以下の4点です。

そのため代わりにJPAでh@Gatter, @Setterを使用しました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?