> For the complete documentation index, see [llms.txt](https://coldbox-orm.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-orm.ortusbooks.com/v5.x/base-orm-service/base-orm-service.md).

# Overview

Base ORM Service - A powerful base service layer for BoxLang ORM (bx-orm) entities.

![class BaseORMService](https://github.com/ColdBox/cbox-cborm/wiki/BaseORMService.jpg)

The *BaseORMService* is a core model class of the module that will provide you with a tremendous gamut of API methods to interact with ORM entities.

{% hint style="info" %}
In cborm 6 the `BaseORMService` keeps the same methods and arguments as cborm 5, but every method now delegates to the `bx-orm` built-in functions (`entityLoad()`, `ormExecuteQuery()`, `entityCriteria()`, ...) running on Hibernate 7. Adobe ColdFusion and Lucee are not supported by cborm 6: use the cborm 5.x series for those engines.
{% endhint %}

## Concept

The idea behind this support class is to provide a good base or parent service layer that can interact with the BoxLang ORM (`bx-orm`, Hibernate) and entities inspired by [Spring's Hibernate Template](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/classic-spring.html#classic-spring-hibernate) support. This means that you don't need to create a service layer class in order to work with ORM entities.

It provides tons of methods for query executions, paging, transactions, session metadata, caching and much more. You can either use the class on its own or create more concrete service layers by inheriting from this class.

## Usage

In order to get started with the base ORM service you need to know how to get access to it. You can do this via WireBox injection DSL or by the model's ID.

### WireBox DSL

The module also registers a new WireBox DSL called `entityservice` which can produce virtual or base orm entity services that you can use to inject into your own event handlers or models.

* `entityservice` - Inject a global ORM service
* `entityservice:{entityName}` - Inject a Virtual entity service according to `entityName`

### Injection

You can also request a Base ORM Service via the registered WireBox ID which is exactly the same as the `entityService` DSL:

```javascript
// Inject
property name="ORMService" inject="BaseORMService@cborm";

// Retrieve
wireBox.getInstance( "BaseORMService@cborm" );
```

### Implementation

Once you have access to the injected base ORM service, you can use it in all of its glory.

{% hint style="danger" %}
**Important:** Please check out the latest [API Docs](https://apidocs.ortussolutions.com/#/coldbox-modules/cborm/) for the latest methods and functionality.
{% endhint %}

```javascript
class {

    property name="ORMService" inject="entityService";

    function saveUser( event, rc, prc ){
        // retrieve and populate a new user object
        var user = populateModel( ORMService.new( "User" ) );

        // save the entity inside a transaction
        ORMService.save( user );

        relocate( "user.list" );
    }

    function list( event, rc, prc ){
        // get a listing of all users with paging
        prc.users = ORMService.list(
            entityName = "User",
            sortOrder  = "fname",
            offset     = event.getValue( "startrow", 1 ),
            max        = 20
        );

        event.setView( "user/list" );
    }

    function index( event, rc, prc ){
        prc.data = ORMService.findAll( "from Permission" );
    }
}
```

Once you have a reference to the base ORM service then you can use any of its methods to interact with ORM entities. The drawback about leveraging the base ORM model is that you cannot add custom functions to it or tell it to work on a specific entity for all operations. It is a simple API, but if you need more control then we can start using other approaches shown below.

## Virtual Services

We also have a [virtual service layer](/v5.x/virtual-services/virtual-entity-service.md) that can be mapped to specific entities and create entity driven service layers virtually. Meaning you don't have to be passing any entity names to the API methods to save you precious typing time.

## Concrete Services

This is where you can create your own class that inherits from our Virtual or Base ORM Service model and either add or override methods. You can read more about it in our [Concrete Services Section](/v5.x/base-orm-service/concrete-services.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-orm.ortusbooks.com/v5.x/base-orm-service/base-orm-service.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
