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 http://yehudakatz.com/2010/01/10/activemodel-make-... *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 Walsh
How to use ActiveRecord to persist POJO, or ideas about mass assignments of attributes to/from POJOs
on 2012-11-01 06:11
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.