Ah yes, just what we need: another ORM...
PikaORM is an object-relational mapping tool for Java.
PikaORM is designed differently than most other Java ORM tools:
- It does not require any code-generation
- It works with POJOs
- It is configured entirely in code, no config files
- It doesn't hide the underlying SQL from you
- The source is in one file, and can be copied-and-pasted into your project if you wish to tweak or fork it
Here is an example of PikaORM in action:
// a POJO model class
class MyModel {
long id;
String str;
}
public static void main(String[] args) {
// create an ORM with a connection string
var orm = new PikaORM("jdbc:sqlite:demo.db");
// create a new model object
var model = new MyModel();
model.str = "Hello PikaORM";
// save it to the database, get the resulting generated id
var id = orm.insert(model);
// load the model from db by id
var fromDb = orm.find(MyModel.class).byId(id);
// print out "Hello PikaORM"
System.out.println(fromDb.str);
}The MyModel class in this example is a POJO and doesn't know
anything about the backing database.
In this case the schema for the table that holds this POJO would look like this:
CREATE TABLE my_models (
id INTEGER PRIMARY KEY,
str_val VARCHAR NOT NULL
);ClassName->class_namesfieldName->field_nameid-> id column/field name<table_name>_id-> foreign key column/field nameversion-> optimistic concurrency column/field name