1

I'm a long time front end developer needing to do some backend work in Java. I'm familiar with database access techniques in both CF and .Net, but haven't had much experience in Java. I'm building an application that must be supported by either myself or much less experienced developers.

Is there a fairly simple to setup and easy to understand DB access system out there for Java? I feel like Hibernate is going to be too much for my team, but that straight up JDBC would have me reinventing the wheel.

Thanks in advance, Robert

Robert Smith
  • 385
  • 4
  • 15

7 Answers7

1

There are lots of alternatives to JPA/Hibernate that are simpler to use. I am partial to sormula since I am the author. You have several options with sormula including zero-configuration, DAO based, active record, or custom.

Jeff Miller
  • 1,424
  • 1
  • 10
  • 19
1

Try ActiveJDBC: http://javalite.io/activejdbc. It is a high performance lightweight ActiveRecord implementation in Java. Comes with everything you need (and probably more). Quick example:

CREATE TABLE people (
  id  int(11) NOT NULL auto_increment PRIMARY KEY,
  first_name VARCHAR(56) NOT NULL,
  last_name VARCHAR(56));

Corresponding model:

public class Person extends Model {}

Query:

List<Person> marks = Person.where("name = ?", "Mark");

Save:

Person p = new Person();
p.set("first_name", "John", "last_name", "Doe").saveIt();

There is a lot more to it, check out at: http://javalite.io/documentation

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
0

Try something different, take a look at JDO.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
0

I personally used MyBatis, as suggested by Daniel, for many projects and it's great. Simply put, MyBatis maps the result table of your SQL query to Java objects, so you still need to write lots of SQL.

In my opinion, MyBatis is great if your database schema does not conform nicely with object oriented design. One of the project I worked on had legacy DB schema that required me to write recursive SQL to retrieve data, and MyBatis works very nicely in that regard.

Alvin
  • 10,308
  • 8
  • 37
  • 49
  • The DB will be brand new for this app, so I don't believe I should have any significant schema problems. My team is used to writing out queries, so that's not a problem. This makes a lot of sense as a way to cut out the middleman writing code to translate table results to objects. It should also be simple enough that anyone can look at it and figure out what it's doing. Looking seriously at this one. – Robert Smith Jun 14 '12 at 20:10
0

Is there a fairly simple to setup and easy to understand DB access system out there for Java?

My ORMLite package was designed to satisfy those specific requirements -- a simple layer on top of JDBC. You can configure your database entities using annotations or programmatically. Supports some mid level ORM features while trying to remain KISS.

Sample entity:

@DatabaseTable(tableName = "accounts")
public class Account {
    @DatabaseField(id = true)
    private String name;
    ...

Sample usage:

// this uses h2 but you can change it to match your database
ConnectionSource connectionSource =
       new JdbcConnectionSource("jdbc:h2:mem:account");
Dao<Account,String> accountDao =
       DaoManager.createDao(connectionSource, Account.class);
// create new table
TableUtils.createTable(connectionSource, Account.class);
// persist an instance of Account
Account account = new Account("Jim Smith");
accountDao.create(account);
Gray
  • 115,027
  • 24
  • 293
  • 354
  • I'll definitely check this out. I may be leaning towards myBatis just because I think it would give my team warm fuzzies to be able to see and adjust the sql statements. Thanks for the response! – Robert Smith Jun 14 '12 at 20:47
0

You can try the Ujorm framework based on a key-value architecture of domain objects. The main features:

  • java compiler discovers the most of syntax errors on a database query
  • easy to configure the ORM model by java source code without XML configurations
  • lazy loading or the one request data loading of relations are supported optionaly
  • database tables, columns and indexes can be optionally updated according to Java meta-model in the run-time
  • no proxy or binary modified business objects
  • very lightweight framework with no library dependencies in the run-time
  • great performance

Sample code:

 Criterion<Item> crn1, crn2, criterion;  
 crn1 = Item.ID.whereGe(1L);  
 crn2 = Item.ORDER.add(NOTE).whereEq("My order");  
 criterion = crn1.and(crn2);  

 Session session = ormHandler.createSession();  
 for (Item item : session.createQuery(criterion)) {  
    Date created = item.getOrder().getDate();  
    System.out.println( item + " : " + created );  
 }
 session.close();
pop
  • 35
  • 4
-1

+1 for MyBatis. It is a good choice if you want to have full control over the SQLs that you use.

sperumal
  • 1,499
  • 10
  • 14