
Bringing Ruby's ActiveRecord to Java - gregpoulos
http://blog.rapleaf.com/dev/2011/03/28/bringing-rubys-activerecord-to-java/
======
pan69
Maybe this could have helped: <http://code.google.com/p/activejdbc>

~~~
stephen
Or my own take on an ActiveRecord-inspired ORM: <http://joist.ws/> :-)

------
nwp
Why not just use JRuby?

~~~
jshen
I was thinking the exact same thing. My superficial reaction is that they
could embed jruby in their java code and use the real active record model.
this would let them reuse the validation logic and all that good stuff.

I'm really curious if they explored this possibility, and if so why they
rejected it.

~~~
alttab
I immediately jumped to this conclusion as well. I judge that it may not have
occurred to them. If most of their experience was in Java they may not have
thought of embedding as a solution.

------
famousactress
Can anyone who's got Hibernate and ActiveRecord experience give a quick shot
on the big differences?

I haven't used ActiveRecord.. but spent years with Hibernate, and consider it
a pretty impecable project compared to other ORMs I've encountered (J2EE's
CMP, and Django's ORM, specifically.

~~~
kpanghmc
I've used NHibernate (which is the .NET port of Hibernate) and Rails
ActiveRecord.

The biggest difference to me is that Rails ActiveRecord encourages you to work
from the database first. That is, you define your database tables and columns
which are then used to generate your classes. In contrast, NHibernate (and I'm
assuming Hibernate as well) encourages you to design your classes first and
worry about persistence later.

There are merits to both approaches. In general, I'd say that Rails
ActiveRecord is much easier to use and get started with while NHibernate
allows for more flexibility in your domain model.

~~~
jarin
If you prefer the flexibility of the class-first model, it might be better to
use something like Mongoid (with MongoDB) instead.

~~~
kpanghmc
Or DataMapper if you want to keep using a relational database as your
persistence medium.

~~~
xentronium
Btw, datamapper has a mongo adapter too, so it isn't restricted to RDBMS.

------
there
remotely related: php-activerecord (<https://github.com/kla/php-activerecord>)
is a good php implementation of activerecord that works pretty much like the
ruby version.

no migration support yet, but the rest of the code is there. i've been using
it in a number of projects for over a year.

------
seasoup
To me the biggest benefit of ActiveRecord is the database introspection to
dynamically create the objects attributes based on the columns in the
database.

This doesn't do that in Java, it parses rails migrations to generate the java
classes for objects with these attributes.

Why is this a problem?

We have a similar setup up where I work, but rails migrations doesn't manage
the database schema, that is managed on the java side. Rails still gets all
changes to the DB in its objects, but using this setup wouldn't work. I was
all excited by the title too, still it's a good solution to their particular
problem.

~~~
Stormbringer
I remember tackling a similar database introspection problem in 2006 I think
it was. Reflection played a pretty big part in the solution if I recall.

I don't remember what exactly it was that I wanted to do, but it might have
been something like building a dynamic table editor. You pull back the
resultset, and then whip up a grid and for each column you assign the column
heading based on the value from the resultset, and then when you go to update
one of the rows you need to remember the name of the column for building the
query dynamically. You have to jump through a few hoops, but it isn't hard.

Anyway, once I discovered the superior technology of JPA I never looked back.

