How to use ActiveRecord to persist POJO, or ideas about mass assignments of attributes to/from POJOs

Greetings. Thanks to decoupling in ActiveModel & ActiveSupport I can
add
mix ins to pojo classes to make them appear as ActiveModel.
In this way I can create view helpers, controllers, routes, etc.
However, I
can’t seem to figure a way to have POJO classes behave as ActiveRecord
(actually persist the pojo)

see

CardApplicant = com.foobar.model.CardApplicant
class CardApplicant

  • mix in activemodel*

  • extend ActiveModel::Naming*
  • include ActiveModel::Serialization*
  • include ActiveModel::Serializers::JSON*
  • include ActiveModel::Serializers::Xml*
  • include ActiveModel::Conversion*
  • include ActiveModel::Validations*

    end

Now my model has the methods in the java class, plus whatever I add to
the
rails model.

Without too much trouble, I can get this to work

resources :card_applicants

and this

def new

  • @card_applicant = CardApplicant.new*
  • respond_to do |format|*
  •  format.html # new.html.erb*
    
  •  format.json { render json: @card_applicant }*
    
  • end*
  • end*

However, in order to use ActiveRecord to persist, I need to create a
separate rails model.
That is then used for persistence and hooked to the controller and when
I
need the pojo, I need to create a new one and mass assign properties to
and
from the activerecord model to and from the pojo. This is expensive and
error prone.

Any ideas or suggestions would be appreciated.

-b

-Brian W.