Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 1.41 KB

README.md

File metadata and controls

66 lines (46 loc) · 1.41 KB

Deprecation Notice: This project is updated and merged into jDBI 3 by Matthew Hall. This repository is not maintained any more.

JPA annotation extension for jDBI

Extension for jDBI to use JPA annotations for mapping/binding instead of JavaBeans conventions.

Usage

Annotate

Annotate your entity with JPA annotations:

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class Something {
    @Column
    private int id;
    @Column
    private String name;
}

Map

Use AnnoMapper to create ResultSetMapper:

ResultSetMapper<Something> mapper = AnnoMapper.get(Something.class);

Or register AnnoMapperFactory as a ResultSetMapperFactory:

@RegisterMapperFactory(AnnoMapperFactory.class)
public interface SomethingDAO {

    @SqlQuery("select * from Something where id = :id")
    Something get(@Bind("id") long id);

}

Bind

Use @BindAnno instead of @BindBean to bind annotated classes.

public interface SomethingDAO {

    @SqlUpdate("update something set name = :s.name where id = :s.id")
    void update(@BindAnno("s") Something something);

}

Maven

<dependency>
    <groupId>me.shakiba.jdbi</groupId>
    <artifactId>jdbi-annotation</artifactId>
    <version>0.1.1</version>
</dependency>