Saturday, March 31, 2007

A Java based ActiveRecord?

One of the things I really love in the Rails-world is working with ActiveRecord. So I thought, someone most have done this in Java too,... no? Here is a short list of existing projects I found:
But none of them seems to have released anything yet :-(

There is so much the Java community can learn from ActiveRecord. Yes, I now it is intrusive on the model by forcing us to inherit its base class. Yes, I know you get the most from it by accepting all its defaults. And yes, you have to demarcate transactions in your code. But it is a lot easier to work with.

We should be able to work around some of these shortcomings while keeping some of the good stuff.

11 comments:

Geert said...

What parts of ActiveRecord do you really like, since there are several things that are simply not possible in Java due to the Ruby's 'method_missing' not being available, for instance.

Madsie said...

Since Rails has no compile-time, the method_missing in Ruby might as well be implemted in Java as a method taking a String.

For instance, you might type "person.name" in Ruby, and in Java you could type "person.get("name")". Both methods has the same deficiencies in type-safety, performance etc.

Per Olesen said...

@geert: What I like the most is "the feel og easiness" when working with ActiveRecord. I've worked with Castor, Hibernate, EJB1.x, EJB2.x, JPA, ... and none of them are so easy to grasp, get started with and do something useful with. That's the "feel of it".

Now, how this can be accomplished in Java, I do not quite know. One thing for instance, is the auto-generation of finders on objects, which, as you say, can be done in Ruby, partly due to method_missing. We might be able to do something alike in Java with a proxy, where all calls land in an "invoke" method.

Tug said...

Have you looked at Grails/Groovy and Gorm ?
- http://grails.codehaus.org/GORM

Per Olesen said...

@tug: Yes, I've had a look at GORM, but it is some time ago. Still, I would need to write my code in Groovy, and I woud like it to in plain Java.

I can see, that GORM has the possibility of writing the domain classes in Java. Thats fine, but I would still have to write my accessing code in groovy, and it only works with finders,

Per Olesen said...

Just found this. Seems like project Slingshot at dev.java.net has something going on. I wonder if it is easy to use outside slingshot!?

John McClean said...

Hi Per,

It's relatively straight forward to get started with DynaModel in Java (it just needs a jdbc.properties file to be present on the classpath). I've only ever run it against MySQL though. And do the dynamic finder-type thing, you need to write your calls in Groovy (define a DAO interface in Java and a Groovy imlementation).

yagmurunsesi said...

thanks
renovationdoctors.com
turizmseyahat.blogspot.com
www.yagmurunsesi.org
yagmurunsesiorg.blogspot.com
turkuntarihi.blogspot.com
websitesiyapamak.blogspot.com
saglik-k.blogspot.com
ders-hane.blogspot.com

Min Cha said...

Hi. I am developing another version. It`s called HiveRecord and based on Hibernate and JPA. Recently, 0.1 version has released.

http://code.google.com/p/hiverecord

Eko SW said...

I stumbled accros your blog when I want to seek, is there any java version of activerecord as in Codeigniter PHP? http://codeigniter.com/user_guide/database/active_record.html

I dunno about Rails, or Grails/Groovy, but in CI, activeRecord is a simple mean of avoiding SQL syntax.

That's what I want :)

Igor Polevoy said...

I'm late to the party, but anyone looked at this: http://code.google.com/p/activejdbc/ ?