Introducing ActiveJpa

Follow up to my previous post on building restful services at ease, I have created a library ActiveJpa that is aimed at avoiding the need to create a layer for DAL. It does so by integrating the data access piece with the models. ActiveJpa attempts to implement the active record pattern on top of JPA to allow operations like ActiveRecord library in ruby.

Visit for samples and usage.

Some sample operations that you can do with ActiveJpa,

    // Get order by id
    Order order = Order.findById(12345L);

    // Get all orders for a customer that are shipped
    List<Order> orders = Order.where("customer_email", "", "status", "shipped");

    // Get all orders for the product category 'books' and paginate it
    Filter filter = new Filter();
    filter.addCondition(new Condition("orderItems.product.category", Operator.eq, "books");
    List<Order> orders = Order.where(filter);

    // Count of orders matching the filter
    Long count = Order.count(filter);

    // Get the first order matching the filter
    Long count = Order.first("customer_email", "", "status", "shipped");

    // Get the unique order matching the conditions
    Long count ="customer_email", "", "status", "shipped");

    // Dump everything
    List<Order> orders = Order.all();

    // Delete all orders matching the filter
    Long count = Order.deleteAll(filter);

    // Check if order exists with the given identifier
    boolean exists = Order.exists(1234L);

    // Save order

    // Delete order

    // Update attributes
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("billingAmount", 1000.0);

    // Find order item by id within an order

    // Search order items by filter with an order


  1. Nick says:

    Can you show an example using Active JPA on how do a Join – Thanks

Leave a Reply

%d bloggers like this: