Extend your JPA with Daobab

In this exercise we will start Daobab in the simplest way.

We need already configured JPA DAO with proper database connection.

Step 1: Add Daobab dependency.


Step 2: Extend dao interfaces with IDao<Entity> and put column definitions into interface.

import io.daobab.structure.IDao;
import test.dao.entity.Pizza;

public interface IDaoPizza extends IDao<Pizza>{

	public default DaoColumn<Pizza,Integer> colName(){
		return define("pizzaId");
	public default DaoColumn<Pizza,String> colName(){
		return define("name");


Step 3: Extend implementation class with AbstractDao<Entity> and point database engine in you DAO. Leave blank in case of MySQL

public class PizzaDao<E> extends AbstractDao<Pizza> implements IDaoPizza{

	@Inject @DataBaseUnit(DictDataBaseUnit.PIZZA_DATABASE)
	private EntityManager em;
	public EntityManager getEntityManager() {
		return em;

That's all. Optionally:

  • describe entity features into interfaces to play with full ORM
  • consider to remove all heavy relations between entities (@OnetoOne,@OneToMany,@JoinColumn etc). Althought Daobab can work with original JPA features code, otftly it's better to do it with Daobab style for perfomance reasons.
  • redirect Daobab to your logger