3

I have a very simple spring application that I am building.

I don't need any relationships or feature rich change tracking/session management or any other fancy features when it comes to an ORM.

I simply want something that maps to my db tables, where I can perform basic CRUD like update/insert/delete/select on a single entity.

I'm using hibernate currently, just wondering what else is out there to expand my knowledge and simplify things.

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

3 Answers3

3

ORM tool themselves are not complicated. In fact, as you you might have noticed, they make the developers life easier when used properly. You have not mentioned what issues you are facing with hibernate which is provoking you to look for simpler alternatives. Almost all of the ORM tools have more or less similar functionality/APIs, as fundamentally they solve the same problem. (Spring supports Hibernate, JDO, iBatis, JPA )

Here is very interesting post on this forum regarding hibernate usage. As a rule of thumb, if you schema has fewer tables (5 - 10 as the post mentions) and the relationship is not very complicated then you should avoid using ORM tools, as this might be an overkill. In this case JDBC would be good enough. I would strongly recommend spring JDBC (since you are already using spring).

Community
  • 1
  • 1
Santosh
  • 17,667
  • 4
  • 54
  • 79
1

I'm not sure if my ORMLite package is the "most" lightweight but I thought I'd at least mention it as a possibility. It has a couple of spring utility classes to help with configurations and has been designed to be simple, easy, and lightweight. Here are the spring documentation:

http://ormlite.com/docs/spring

Here is the getting started section of the manual. There is also a spring wiring example that you can take a look at:

Here's some sample spring configs from the docs:

<!-- URL used for database, probably should be in properties file -->
<bean id="databaseUrl" class="java.lang.String">
    <!-- we are using the in-memory H2 database in this example -->
    <constructor-arg index="0" value="jdbc:h2:mem:account" />
</bean>

<!-- datasource used by ORMLite to connect to the database -->
<bean id="connectionSource" class="com.j256.ormlite.jdbc.JdbcConnectionSource"
    init-method="initialize">
    <property name="url" ref="databaseUrl" />
    <!-- probably should use system properties for these too -->
    <property name="username" value="foo" />
    <property name="password" value="bar" />
</bean>

<!-- abstract dao that is common to all defined daos -->
<bean id="baseDao" abstract="true" init-method="initialize">
    <property name="connectionSource" ref="connectionSource" />
</bean>

<!-- our daos -->
<bean id="accountDao" class="com.j256.ormlite.examples.common.AccountDaoImpl"
    parent="baseDao" />
<bean id="deliveryDao" class="com.j256.ormlite.spring.DaoFactory"
  factory-method="createDao">
    <constructor-arg index="0" ref="connectionSource" />
    <constructor-arg index="1" value="com.j256.ormlite.examples.spring.Delivery" />
</bean>
Gray
  • 115,027
  • 24
  • 293
  • 354
0

I used MyBatis v3.0.4 with Spring v3.0 and it worked really well. We had high performance requirements and it was able to meet them - well, it didn't get in the way. It is also flexible enough to allow complicated things, if necessary. Very little setup required.

Mark
  • 1,884
  • 2
  • 25
  • 36