ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Lightweight R/O Mapping
Pages: 1, 2, 3, 4, 5, 6, 7

Step by Step

Let's tackle a little persistence problem. To read a list of Jedi objects from the database, we assume that the result set that is delivered looks like the table below. Please note that we are not going to rely on tables in the following discussion, even though the examples are actually based on tables. In general, we're just expecting tabular data that might have been put together using several SQL joins and spanning more than just one table or view. (Also, apologies to all Star Wars fans for any inconsistencies.)

jedi_id  name             force_rating  age  alive 
-------- ---------------- ------------- ---- ----- 
1000     Obi Wan Kenobi   9.40          30   0
1001     Luke Skywalker   7.20          19   1
1002     Yoda             10.00         912  1

Let's define a simple class called Jedi.

public class Jedi {

   private Integer _id;
   private String _name;
   private Double _forceRating;
   private Integer _age;
   private Boolean _alive;

   public void setId( Integer id ) {
      _id = id;
   public void setName( String name ) {
      _name = name;
   public void setForceRating( Double fr ) {
      _forceRating = fr;
   public void setAge( Integer age ) {
      _age = age;
   public void setAlive( Boolean alive ) {
      _alive = alive;

   index=0, isAutoIdentity=true)
   public Integer getId() {
      return _id;
   @ParameterAssociation(name="@name", index=1)
   public String getName() {
      return _name;
   public Double getForceRating() {
      return _forceRating;
   @ParameterAssociation(name="@age", index=3)
   public Integer getAge() {
      return _age;
   @ParameterAssociation(name="@alive", index=4)
   public Boolean getAlive() {
      return _alive;

What happened here? You see two kinds of annotations above the getter and setter methods of that class.

The annotation @ColumnAssociation is used to connect the setter methods of the JavaBean to a column from the result set, so that the tabular data from the database can be written to the bean properties by Amber. The annotation @ColumnAssociation applies to the setter methods only, because Amber uses these annotations to find and call those methods with the corresponding values after reading the data from the database.

Pages: 1, 2, 3, 4, 5, 6, 7

Next Pagearrow