/spring-load-entity

Auto load entities from database with EntityManager, by simply annotating fiels with @LoadEntity(longId)

Primary LanguageJavaMIT LicenseMIT

spring-load-entity

Auto load entities from database with EntityManager, by simply annotating fiels with @LoadEntity(longId)

java-jdk spring-boot codecov circleci

Configuration

<repositories>
    <repository>
        <id>myMavenRepo</id>
        <url>https://mymavenrepo.com/repo/H7y9TxxC8tlHnK4oS5RL/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>romajs.spring</groupId>
        <artifactId>spring-load-entity</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

At your @SpringBootApplication, add the following:

@ComponentScan(basePackages = {"com.mypackage", "romajs.spring"})

Usage

@RunWith(SpringRunner.class)
@SpringBootTest
public class LoadEntityTest {

    @LoadEntity(1L)
    private DemoEntity demoEntity;

    @Test
    public void shouldFoundEntity() {
        Assert.assertNotNull(demoEntity);
    }
    
}

@Entity
public class DemoEntity {

    @Id
    private Long id;

    @Column
    private String name;
    
    // getters & setters
}

For spring boot tests:

  • Works with flyway script loading
  • Does not work with data.sql (possibly by some bug with spring boot loading data.sql and BeanPostProcessor)