Quantcast

Java integration strategies

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Java integration strategies

M Stewart
I have an existing Java project that uses Hibernate-based data model and I'd like to be able to develop a grails app that uses that model to provide a front end UI for it. The domain classes (and all the rest of the project) exist in a separate project/directory (outside of my grails application.) All the Grails doc on using Java domain classes assumes you will be putting the .java files inside the grails app directory. I can't just copy the domain classes into the grails-app/domain (because they have other dependencies on other classes) though I can copy the .jar files with the complete set of classes into the lib directory. With the .jar in the grails' lib directory and a hibernate.cfg.xml file pointing to the appropriate package and class I had hoped to be able to create a simple controller for each java domain class as:

import com.x.y.Foo;

class FooController {
 
  def scaffold = Foo

}

Alas, on startup, this yields the following errors:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: com.x.y.Foo, for columns: [org.hibernate.mapping.Column(instance)]
Caused by: org.hibernate.MappingException: Could not determine type for: com.x.y.Foo, for columns: [org.hibernate.mapping.Column(instance)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
        at org.hibernate.mapping.Property.isValid(Property.java:185)
        at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
        at org.hibernate.cfg.Configuration.validate(Configuration.java:1099)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284)
        at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.buildSessionFactory(GrailsAnnotationConfiguration.java:95)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:804)
        at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.newSessionFactory(ConfigurableLocalSessionFactoryBean.java:87)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:744)


Any recommended strategies to achieve what I'm trying do? Anyone else trying to achieve this sort of thing? Seems like it would a common case in enterprise settings.

Cheers,
Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

pledbrook
> import com.x.y.Foo;
>
> class FooController {
>
>   def scaffold = Foo
>
> }

The problem here may simply be that you can't use dynamic scaffolding
with non-groovy domain classes, although I'm not sure why that would
be the case. Maybe because it expects 'id' and 'version' fields? Have
you tried 'grails generate-controller' or 'grails generate-all'?

Cheers,

Peter

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

M Stewart
Peter Ledbrook wrote
> import com.x.y.Foo;
>
> class FooController {
>
>   def scaffold = Foo
>
> }

The problem here may simply be that you can't use dynamic scaffolding
with non-groovy domain classes, although I'm not sure why that would
be the case. Maybe because it expects 'id' and 'version' fields? Have
you tried 'grails generate-controller' or 'grails generate-all'?
Thanks for the response, Peter.

Actually you _can_ use dynamic scaffolding with java domain classes. If you have a domain class defined in a Bar.java file that sits in grails-app/domain/com/x/y and a matching groovy class,
BarController, in grails-app/controller everything works fine. Or so I've observed anyway. If, as in my case, the .java file doesn't exist in the grails application, however, you'll see the errors I reported.

FWIW I can also have grails generate the controller class but again this requires that the domain class .java file be physically present in the Grails application. I'm trying to reference the class through the .jar in the lib directory the generate-controller command will fail because it can't find the named domain class.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

M Stewart
In reply to this post by M Stewart
While it's not nearly as sexy and cool it turns out that using xml mapping files for my java domain classes works fine when the .java file itself is not present in the grails application. I've now been able to use Groovy domain classes, Java domain classes (where the .java file lives in src/java) and xml mapped Java domain classes (where the .java file resides *outside* the Grails application.). All in a single Grails app.

 I do still wonder if the annotations methodology ought to work. Hmm....

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

pledbrook
On 06/09/07, M Stewart <[hidden email]> wrote:
>
> While it's not nearly as sexy and cool it turns out that using xml mapping
> files for my java domain classes works fine when the .java file itself is
> not present in the grails application. I've now been able to use Groovy
> domain classes, Java domain classes (where the .java file lives in src/java)
> and xml mapped Java domain classes (where the .java file resides *outside*
> the Grails application.). All in a single Grails app.
>
>  I do still wonder if the annotations methodology ought to work. Hmm....

This may be the same problem:

  http://www.nabble.com/Problem-with-an-Hibernate-mapping-tf4055969.html

It may be worth adding a feature request to JIRA for this, although
I'm not sure it will make 1.0. I think Grails should aim to make
integration with existing Hibernate domain models as smooth as
possible, though.

Cheers,

Peter

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

M Stewart
Peter Ledbrook wrote
>...
>  I do still wonder if the annotations methodology ought to work. Hmm....

...

It may be worth adding a feature request to JIRA for this, although
I'm not sure it will make 1.0. I think Grails should aim to make
integration with existing Hibernate domain models as smooth as
possible, though.
I agree. I'm very much in a "sales" position at work (a big, well known American tech company) where it comes to Grails. Being able to drop a jar of annotated classes into the lib directory and have Grails be able to use it would be absolutely killer for us.

Thanks for the feedback, Peter.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

ihery
M Stewart wrote:
> I agree. I'm very much in a "sales" position at work (a big, well known
> American tech company) where it comes to Grails. Being able to drop a jar of
> annotated classes into the lib directory and have Grails be able to use it
> would be absolutely killer for us.
>  
This feature is already fully supported as described in
http://www.infoq.com/articles/grails-ejb-tutorial

We've used it on two big projects and this feature only is a BIG
productivity enhancer !

Bye,

--
..........................................................
Ismaël Héry
Architecte
OCTO Technology
 ..........................................................
50, Avenue des Champs-Elysées
75008 Paris
Tél : (33) 1 58 56 10 00
Fax : (33) 1 58 56 10 01
GSM : (33) 6 12 88 02 15
www.octo.com
...........................................................



---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

graemer
On 9/7/07, Ismaël Héry <[hidden email]> wrote:

> M Stewart wrote:
> > I agree. I'm very much in a "sales" position at work (a big, well known
> > American tech company) where it comes to Grails. Being able to drop a jar of
> > annotated classes into the lib directory and have Grails be able to use it
> > would be absolutely killer for us.
> >
> This feature is already fully supported as described in
> http://www.infoq.com/articles/grails-ejb-tutorial
>
> We've used it on two big projects and this feature only is a BIG
> productivity enhancer !

It may be an unconfirmed Grails 0.6 bug. If someone can post a sample
app that demonstrates the probem in JIRA we can look at it

Cheers

>
> Bye,
>
> --
> ..........................................................
> Ismaël Héry
> Architecte
> OCTO Technology
>  ..........................................................
> 50, Avenue des Champs-Elysées
> 75008 Paris
> Tél : (33) 1 58 56 10 00
> Fax : (33) 1 58 56 10 01
> GSM : (33) 6 12 88 02 15
> www.octo.com
> ...........................................................
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Java integration strategies

M Stewart
graemer wrote
It may be an unconfirmed Grails 0.6 bug. If someone can post a sample
app that demonstrates the probem in JIRA we can look at it
Actually it looks like I was wrong (again.) The errors in the stack trace are actually complaining about the way I've got some of the properties mapped. Basically I've got a non-java.lang.* class property and Hibernate is rightly complaining that it doesn't understand the data type:

org.hibernate.MappingException: Could not determine type for: com.x.y.Foo, for columns: [org.hibernate.mapping.Column(instance)]

Sorry for the bandwidth...

Loading...