[Java] SpringBoot + Doma2 + H2

I tried the official tutorial. https://github.com/domaframework/doma-spring-boot

application.properties


doma.dialect=h2

pom.xml


<!--h2 added-->
<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <scope>runtime</scope>
</dependency>

<!--Doma related addition-->
<dependency>
  <groupId>org.seasar.doma.boot</groupId>
  <artifactId>doma-spring-boot-starter</artifactId>
  <version>1.4.0</version>
  <exclusions>
    <exclusion>
      <groupId>org.seasar.doma</groupId>
      <artifactId>doma-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.seasar.doma</groupId>
  <artifactId>doma</artifactId>
  <version>2.29.0</version>
</dependency>

Entity


import org.seasar.doma.Entity;
import org.seasar.doma.GeneratedValue;
import org.seasar.doma.GenerationType;
import org.seasar.doma.Id;

@Entity
public class Reservation {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer id;
    public String name;
}

Dao


import java.util.List;

import org.seasar.doma.Dao;
import org.seasar.doma.Insert;
import org.seasar.doma.Select;
import org.seasar.doma.boot.ConfigAutowireable;
import org.springframework.transaction.annotation.Transactional;

@ConfigAutowireable
@Dao
public interface ReservationDao {
    @Select
    List<Reservation> selectAll();

    @Insert
    @Transactional
    int insert(Reservation reservation);
}

Error shooting

If a build error occurs ...

Reference: https://doma.readthedocs.io/en/2.5.0/build/ [Build with Eclipse] -Enable annotation processing ・ Factory Path setting

Recommended Posts

[Java] SpringBoot + Doma2 + H2
VisualStudioCode + Java + SpringBoot
Java
[Java & SpringBoot] Environment Construction for Mac
Consideration on Java Persistence Framework 2017 (2) Doma2
Java
[Java] Connection with local DB (IntelliJ + SpringBoot)