> For the complete documentation index, see [llms.txt](https://db.jodd.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://db.jodd.org/object-mapping/mapping-to-a-bean.md).

# Mapping to a bean

There are cases when you have to write complex queries with some calculations, string manipulation, etc. when some result set columns are calculated and not simple table columns values. The question is how to map such columns using *DbOom* and template SQL.

One answer is simple: you can map such result set into simple types, like `Integer`, `String`, etc. classes. However, it would be more convenient if you can map such result into a bean.

To do that, you can create a view in database. However, there are some cases when you can't use views. Do not worry, *DbOom* can help you anyway. Just use `$C` template-sql macro as alias column name.

Let's focus on the following sql:

```sql
    select g.ID + 10, UCASE(g.NAME), g.* from GIRL g where g.ID=1
```

Two first columns are calculated ones. As said, we can map this result to: `Long.class, String.class, Girl.class`. But lets see how we can map first two columns into the some `Bean1` class, a pure POJO.

First thing is to annotate `Bean1` class with `@DbTable` and `@DbColumn` annotations, as it is a mapped bean.

Then, you can write above query using the following template-sql:

```sql
    select $g.id + 10 as $C{Bean1.sum}, UCASE($g.name) as $C{Bean1.bigName}, $C{g.*}
    from $T{Girl g}
    where $g.id=1
```

The key point here is to map columns using `$C` macro and the bean name.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://db.jodd.org/object-mapping/mapping-to-a-bean.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
