SQL2JAVA Overview

SQL2JAVA is a free, open source object-relational mapping tool.

It enables Java developers to quickly map a relational database schema to a set of classes.

The generated source code uses standard JDBC methods for persistence, and there is no runtime library required.

Note that 2 formers SQL2JAVA project admin have created SpringFuse, a Java code generator that generates the source code of a complete web-application based on Hibernate, Spring, Spring MVC, Spring Security, etc.

Key Features

From all the features SQL2JAVA has, what are the key features that makes it really worth my download and my time evaluating it ?

SQL2JAVA is simple

SQL2JAVA source code is simple, its design is simple, so it is easily modifiable and extendable to fit your needs.

The generated code is simple and documented, so it is easily readable.

SQL2JAVA generates code

Is that supposed to be a key feature ?

Isn't hibernate and consors generating on-the-fly code using dynamic proxies that are driven by XML configuration files whom are themselves generated via embeded xdoclet javadoc tags ?

The point is that this kind of software is great, often technologically speaking they are damn great, but their learning curve are damn steep, and when an exception arise, you are damn lost ...

With SQL2JAVA if you have an exception, you have the filename and its line number, so you just read the line and you know EXACTLY what is the exception about !

... as you would do for your own code...


Good / Easy for Because of ...
Learning 5 minutes to setup, generate and launch a real example.
Installation Install ant, type few simple command lines and you're done.
Documentation Generates inline documentation that is usable.
Configuration Automatic mapping of the database fields.
Database Support for Oracle, MYSQL, HSQL, and any database that comes with a JDBC driver that supports retrieval of an auto-generated key.
Identity Retrieves auto-generated keys (Oracle sequence, MYSQL auto_increment, HSQL identity, JDBC 3.0 auto-generated keys, etc...)
Transaction Convenient transaction handling.
Connectivity Uses datasource or simple Driver getConnection.
Performance Performs update/save only when needed.
Performance Uses prepared statements so your database do not have to reparse your queries every time.
Configuration Includes a listener for lifecycle events, so you add code before and after insert, update and delete
Manipulation Requires minimal knowledge of SQL (it is of course always good to have some).
Relationship Manages 1-to-1, many-to-1, and many-to-many relationships.
Extension Easily extendable, both the generator AND the generated code which is template based.
Building It comes with a ready to work example and ant script.

Database support

SQL2JAVA generates an easy-to-use and powerful database layer API to access a given relational database through a JDBC-compliant driver.

It is currently in use in production environments with Oracle, SQL Server, MySQL, and more...

Generating an API for a database not yet supported is very easy, you just need to edit sql2java.properties!

In fact, if your jdbc driver / database supports retrieval of auto-generated keys, then it is already supported by SQL2JAVA.


The project is hosted at SourceForge where you may submit feature requests, bug reports, etc...

Your feedback is important to improve this tool.


SQL2JAVA comes with features ... and constraints.

Very complex schema

SQL2JAVA does not handle everything for you, if your database schema is very complex, it might be lost.

Just generate the code for your database, and see it for yourself.