Result completer

When you want to complete entity with additional data, you can do this by function provided into query.
Daobab provides functionality to attach related entities or fields, without hardcoding relations into entity definition.

Attach related entities during query execution (EAGER):

  • create into entity a location for related data. Use @Transient to omit this field in JPA.
  • @Entity
    public class Pizza implements RelatedToPizza,RelatedToName,RelatedToDescription{
    	private List<PizzaPrice> priceList;
    	public List<PizzaPrice> getPriceList() {
    		return priceList;
    	public void setPriceList(List<PizzaPrice> priceList) {
    		this.priceList = priceList;
  • Into main Query, provide into completeEntity metod, subquery to read the attached data
  • List<Pizza>pizzasWithPriceList= Select.from(daoPizza)
  • Remember about performance.
    In this case you have pizzasWithPriceList.size()+1 queries to execute on database.
    To minimise database usage, use Daobab Cache for daoPizzaPrice. So that the database will be hit just by one query.
  • Attach related entities later, on demand (LAZY):

    Lazy loading requires Supplier provider to execute query in future

  • Add supplier field into entity. Remember about @Transient
    	private transient Supplier<List<PizzaPrice>> supplierPizzaPrice;
  • Into get method, execute the supplier and get the objects when field is empty.
  • 	@Transient
    	private transient Supplier<List<PizzaPrice>> supplierPizzaPrice;
    	public List<PizzaPrice> getLazyPizzaPriceList(){
    		if (priceList==null==false||getSupplierPizzaPrice()==null) return getPriceList();
    		return getPriceList();

    Now our lazy loading Select looks like this:

    List<Pizza>pizzasWithPriceList= Select.from(daoPizza)

    Cascaded usage

    Of course, the second select providing attached entities can contain attached objects as well... and so on... there no limit .
    The only limit is your imagination. Thanks to Daobab, you can create cascaded objects on demand, exactly in the way you need and also in use of cache to speed up the queries.