/jibernate

The JPA (Java Persistence API) module based on the Hibernate ORM framework with the enhanced and simplified query and expression modules.

Primary LanguageJavaApache License 2.0Apache-2.0

jibernate

Build Status Coverage Status Codacy Badge License

The JPA (Java Persistence API) module based on the Hibernate ORM framework with the enhanced and simplified query and expression modules.

Overview

This is a JPA (Java Persistence API) module based on the Hibernate ORM framework. The entity and column mapping is based on annotations rather than a standalone mapping XML file. For example, there is a student table in the database:

CREATE TABLE `student` (
  `id`                 bigint(20)   NOT NULL AUTO_INCREMENT,
  `first_name`         varchar(255) DEFAULT NULL,
  `last_name`          varchar(255) DEFAULT NULL,
  `dob`                datetime     DEFAULT NULL,
  `gpa`                double       DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

So the persistence entity class which maps to this student table will look like this:

@Entity
@Table(name="student")
public class Student extends AbstractEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")           private Long      id;
    @Column(name="first_name")   private String    firstName;
    @Column(name="last_name")    private String    lastName;
    @Column(name="dob")          private Date      dob;
    @Column(name="gpa")          private double    gpa;
}

Also, this module avoid writing the persistence file (XML) so that you will not be trapped by too detailed database configurations, you can use specific database configuration class for passing your basic database connection parameters to this module. For example:

MysqlDbConfig dbConfig = new MysqlDbConfig("config/MysqlDb.properties").initialize();
MysqlEntityManagerDao dao = = new MysqlEntityManagerDao(dbConfig);

Another highlight of this project is it simplify the query, you don’t have to construct a long JPQL statement. It comes up the idea of Expression which has chain methods for you build up a complex query.

EntityQuery<Student> query = new EntityQuery<Student>(Student.class);
query.setCriteria(new Expression("firstName", Expression.EQUAL, "John"));
List<Student> studentList = dao.read(query);

Getting Started

Please see our Wiki page.

Documentation

Please see our Wiki page.

Download

Contributing

License

Apache-2.0

Authors