Fast ORM for agile development
Follow to: ActiveJDBC documentation
5 minute introduction
For a simple example we will use a table called PEOPLE created with this MySQL DDL:
CREATE TABLE people ( id int(11) NOT NULL auto_increment PRIMARY KEY, first_name VARCHAR(56) NOT NULL, last_name VARCHAR(56), created_at DATETIME, updated_at DATETIME );
ActiveJDBC infers DB schema parameters from a database. This means you do not have to provide it in code.
The corresponding model looks like this:
There is no code in the body of the class, and yet it is fully functional and will map to a table called
PEOPLE automatically. Read more on English Inflections.
How to query
Simplest query example:
1 2 3
where() method takes a snippet of real SQL. The first line above will generate this statement:
SELECT * FROM people WHERE first_name = 'John'.
Finder methods can also be parametrized:
1 2 3
where() method takes a vararg, allowing unlimited any number of parameters to be passed into a statement.
Paging through data
1 2 3 4
This query will ensure that the returned result set will start at the 21st record and will return only 10 records, according to the
orderBy. The ActiveJDBC has a built in facility for various database flavors and it will generate appropriate SQL statement that is specific for a DB (Oracle, MySQL, etc) and is efficient. It will not fetch all records, starting with 1.
Creating new records
There are several ways to do this, and the simplest is:
1 2 3 4 5
There is also a shorthand version of doing the same:
and yet shorter one :
Updating a record
Deleting a record
There are more ways to delete, follow Delete cascade to learn more.
If you want to get started, follow these links:
Please, see Getting Started for a working example.
Look through these:
Other working examples:
Here is the JavaDoc for ActiveJDBC
- Infers metadata from DB
- Convention-based configuration.
- No need to learn another QL. SQL is sufficient
- Code often reads like English
- No sessions, no "attaching, re-attaching"
- No persistence managers.
- Models are lightweight, simple POJOs
- No proxy-ing. What you write is what you get (WYWIWYG :))
- No getters and setters. You can still write them if you like.
- No DAOs and DTOs
- No Anemic Domain Model
Currently the following databases are supported:
Adding a new dialect is relatively easy. Just look at commits on this branch: h2integration
Please, refer to the Releases page.
Getting the latest version
For the latest version refer to ActiveJDBC on Maven Central. If you use Maven add this to your pom:
1 2 3 4 5
Do not forget to replace LATEST_VERSION with the latest version deployed to Maven Central (see above)
Current latest version: 1.4.13.
Additionally, configure Instrumentation plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13
Or download from: ActiveJDBC Instrumentation plugin on Maven Central
Getting latest snapshot versions
If you are using Maven, add these repositories to your pom:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
If you are not using Maven, you can pull down the latest snapshots from here: JavaLite Repo
How to comment
The comment section below is to discuss documentation on this page.
If you have an issue, or discover bug, please follow instructions on the Support page