JRoR: Co-existing with Java/Hibernate back end

  • I submitted this through the Web forum interface and never saw it come
    through on the list, so I wasn’t sure if it made it through. So I’m
    reposting it here. Could be that it made it through and it’s a crappy
    question and I’m ok with that ;). So if it’s a repost, sorry. If it’s
    not, now you know *

All,

I’m looking at a project where I’m being asked to focus mostly on the
front-end development. I don’t have all of the details yet, but the
implication is that the model layer is going to be handled completely in
Java, presumably using Hibernate.

This gets me thinking about how to manage the model side of things with
Rails. Do I effectively create a set of non-DB backed models and then
shuttle data back and forth to Hibernate? This feels really not good to
me.

I’m looking for people who have experience working on a JRoR project
where Hibernate was involved. Did you run into issues where the Rails
model layer and Hibernate where competing for management of the same
model objects? Or did you just give each framework non-overlapping
groups of models to manage?

Any feedback is appreciated.

The right answer is not “just use Rails for everything,” btw ;).

Thanks,
Wes G.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Wes, without having specifics on your project it is hard to say;
However, I can say that I have had great success with Spring,
Hibernate, RMI, and JRuby. No issues other than coercing objects
between Ruby and Java, which boiled down to some form of to_java, or
getting it right. There are probably other things to know, but I
suspect there are no show stoppers.

On Wed, Feb 25, 2009 at 12:31 PM, Wes G. [email protected] wrote:

implication is that the model layer is going to be handled completely in
model objects? Or did you just give each framework non-overlapping
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Johnny,

So, in your case, you weren’t using Rails I assume?

If so, where did you get your “bang for the buck” from the Ruby side of
things? Just curious.

Wes

Johnny P wrote:

through on the list, so I wasn’t sure if it made it through. So I’m

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

a project i worked on had a similar architecture: some backend
processing in java+hibernate and a web frontend in rails. we ended up
changing the schema on the hibernate side to make it activerecord
friendly (plural table names, underscores etc) and then accessed data
using AR on the rails side.

then we decided to get rid of hibernate completely (it was too much
effort maintaining a parallel model hierarchy) and moved the backend
processing from Java to JRuby+AR, which worked fine (there’s very
little advantage of using hibernate in terms of functionality now,
besides better “legacy db” support).

you might be able to create JRuby model proxies, which do some clever
things with hibernate metadata (autogenerate methods a la AR). i think
some people tried that, but don’t remember the names of the projects.

jan

On 25 Feb 2009, at 20:31, Wes G. wrote:

implication is that the model layer is going to be handled
I’m looking for people who have experience working on a JRoR project
Wes G.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Jan,

That’s kind of what I foresee could happen. I definitely wouldn’t
bother changing the schema just to meet Rails conventions - that’s not
really necessary.

One upside of a “parallel model” approach is that you can treat the
Rails models as non-table backed and purely UI-focused, treat the Java
models as the “real” models and then marshal data across the “R-J
junction” however you want (e.g. aggregate N Java models into one Rails
model or whatever).

Thanks for the thoughts.

WG

Jan B. wrote:

little advantage of using hibernate in terms of functionality now,

  • I submitted this through the Web forum interface and never saw it
    Java, presumably using Hibernate.
    groups of models to manage?

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

No not rails, but Swing. The bang for the buck was I could develop
tools with gui frontends much faster and usually in one jruby file.

On Thu, Feb 26, 2009 at 9:02 AM, Wes G. [email protected] wrote:

  • I submitted this through the Web forum interface and never saw it come
    implication is that the model layer is going to be handled completely in
    model objects? Or did you just give each framework non-overlapping
    To unsubscribe from this list, please visit:
    http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

We’ve been developing Jruby/Rails apps with Java/Spring/Hibernate for
long time now and very successfully. Below is a post from long ago,
but it’s still pretty accurate.

http://www.nabble.com/Re%3A-views-controller-in-Ruby-<%3D>-domain-and-data-access-in-Java-p15035460.html

I’d also add that another big gain has been the ability to re-open our
java classes and extend them for our Ruby applications as well as
being able to do BDD with rspec for java and ruby classes alike.

In java we had the full layered architecture(domain model/dao/service)
with dependency injection via Spring. From the outside in perspective,
it seems a bit clunky sometimes dealing with 3 different layers to
accomplish any given thing, but it was pretty much necessary so that
mocks/stubs could be injected for testing. A static finder method in
java left no easy way to hook into the return value without hitting
the database. In Jruby there are no testability tradeoffs to making
the API look the way I’d prefer it to be.

ex.

class Manuscript
def self.find_by_accode(accode)
SpringAppContext.get_bean(:manuscriptDAO).findByAccode(accode)
end

def save

SpringAppContext.get_bean(:manuscriptService).saveManuscript(self)
end

...

Using rspec, Manuscript.should_receive(:find_by_accode).and_return(m)
is not a problem.

I can’t say I’d choose to do a new Rails app from scratch using
Hibernate and Spring, but accessing our pre-existing API from JRuby is
even easier than from plain Java.

-lenny

On Feb 25, 2009, at 3:31 PM, Wes G. wrote:

implication is that the model layer is going to be handled
I’m looking for people who have experience working on a JRoR project
Wes G.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email