Search code examples
javadatabasehibernateeclipselinkdata-access-layer

Automatic data access layer generation


Hibernate and eclipselink are the most popular DAL frameworks for Java. From what I understand they map object that the programmer created to database relations and stored procedures that are created automatically.

What are the pros and cons of using this method versus:

  1. Writing your own DAL, assuming my project is small-medium sized.

  2. Finding a framework (if exists ?) that will it the other way - create classes from database relations and stored procedures.

Personally, I feel more comfortable with reasoning about database relations rather than Java (or any programming language) classes.


Solution

  • Your understanding of JPA is wrong. JPA (of which Hibernate and EclipseLink ar two implementations) is an ORM: Object Relational Mapper. Some prefer designing Java objects and deduce the database schema from these objects. Others prefer designing a database schema, and deduce Java objects from this schema.

    Both approaches are possible, and JPA doesn't assume any of those approaches. It specifies how Java objects and their associations can/must be mapped to tables.

    Advantages over writing your own DAL:

    • you don't have to,
    • it's much more efficient
    • it's standard, and a whole lot of developers know how it works
    • it's better designed, and has less bugs
    • what you learn will be usable on many other projects

    Advantages over finding a framework which creates classes from database relations:

    • Not applicable: JPA is such a framework.