13

I am looking for a Java implementationation of the ActiveRecord pattern which is built on top of Hibernate.

In .Net there is a open source project Castle Windsor ActiveRecord which implements the ActiveRecord pattern on top of NHibernate.

I'm looking for something like this, except sitting on top of the NHiberate persistence frameowork for Java.

Iker Jimenez
  • 7,105
  • 9
  • 49
  • 46
marshally
  • 3,541
  • 2
  • 23
  • 26

6 Answers6

10

I released a project called ActiveJDBC: http://javalite.io/. This is what you are looking for

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • It does not support eager loading multiple levels of association. For me, it's a big no-no. – Aetherus Feb 08 '21 at 03:35
  • it does support multiple levels of associations, and it does support of a form of eager loading, however, in a modern webapps, you do not want to do that – ipolevoy Feb 08 '21 at 20:47
  • Can you give an example of how to do it? I can't find the documentation, and the documentation of the `LazyList#include` method explicitly notes that "This method will not follow related models, but rather only relationships of the current one." – Aetherus Feb 14 '21 at 14:31
  • @Aetherus, this is correct, the eager loading works down just one level, and you need to specify that. Imagine you are pulling users, and their roles - if if did load eagerly, it would walk in circles till it loaded all users and all roles, lol. In any case, eager loading has its place and I personally do not like it in web apps anyway. If you want, you can open an issue here: https://github.com/javalite/javalite/issues and provide more info so I could suggest something better. – ipolevoy Feb 16 '21 at 00:16
3

I would say GORM is a better pattern for using with Java that ActiveRecord. ActiveRecord ultimately requires more work and more coding than GORM. From what I can tell, Django follows the GORM model more than it does the AR model, so that model might be something worth looking into, especially given that Java probably wouldn't lend itself to dynamic getters and setters as Ruby does (unless you starting delving into generating bytecode on the fly, but your compiler and IDE wouldn't like that very much).

2

Well, GORM in Grails cannot be detached from Grails - until version 1.1 is out at least. And frankly, there are quite few differences between GORM and AR (eg: in Grails, you model your domain objects and GORM will infer the database structure whereas in AR, you have your table on the one hand, and your object on the other). Oh, and one more difference is that GORM has a lot of quirks to it. Notice I didn't say bugs...

Anyway, here's another similar post here on stackoverflow which may cover what you're after: Is there an implementation of the ActiveRecord pattern in Java like the one from Ruby?

Cheers,

Rollo

Community
  • 1
  • 1
Rollo Tomazzi
  • 3,120
  • 3
  • 28
  • 21
1

Actually, I have been working on AR - like framework in Java, first blog: http://igorpolevoy.blogspot.com/ cheers, igor

ipolevoy
  • 19
  • 1
1

GORM in Groovy / Grails?

Dutow
  • 5,638
  • 1
  • 30
  • 40
0

Scooter Framework has an implementation of ActiveRecord very similar to Ruby on Rails: http://www.scooterframework.com/

rtacconi
  • 14,317
  • 20
  • 66
  • 84