Menu

orm_querying

Luis M. Villa

Starting with MILK's ORM

This tutorial is based on the tests embedded in MILK's source code. You can find all code in it.

First of all: as we did when executing SQL queries over a database, we'll use a method to access MILK's ORM features. This method will be available only if our database extends from DbWithOrm (instead of Db). So, let's start:

import javax.sql.DataSource;

import net.sourceforge.milk.DbWithOrm;
import net.sourceforge.milk.orm.configuration.OrmConfigurationBuilder;

public class IssuesDbExamples extends DbWithOrm {

    @Override
    protected void configureOrm(final OrmConfigurationBuilder ormConfig) {
        // Now we have to implement this method. Using the ormConfig parameter,
        // we'll customize all the parameters of the ORM for our environment.
    }

    @Override
    protected DataSource createDataSource() {
        // ... as before ...
    }
}

For now, we'll not configure anything, let's go step by step. Let's fetch an object by its id


Related

Wiki: examples_toc
Wiki: orm_examples
Wiki: orm_get_by_id

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.