0
votes

I inherited a Grails project that has both Hibernate .xml files AND Domain classes for the Model. This thread leads me to believe that that is not correct. I am upgrading the project from 1.0.3 to 1.3.7. The way I understand it, it worked in 1.0.3 but is no longer supported after 1.2.

The Hibernate XML files provide all of the mappings to the objects, but the same objects in the Domain have properties and methods that extend the objects, so both make sense to keep.

  • Is there any way I can still have the best of both worlds (keeping the Hibernate Mapping as well as the Domain objects)?

  • If not, What is the recommended way to proceed?

UPDATE:

I want to be able to have a Hibernate XML file Book.hbm.xml as well as a file /src/groovy/Book.groovy that has extra methods on the class.

From the documentation it looks like they are treated as two separate things:

Q: How can I access domain classes from sources in src/groovy?

Sometimes, you are developing some utility classes that live in src/groovy and which you intend to use from Services and other artifacts. However, as those classes are pre-compiled by Grails, it is not possible to instantiate them and write things like Book.findByTitle("Groovy in Action"). But fortunately, there is a workaround since it's possible to do this:

import org.codehaus.groovy.grails.commons.ApplicationHolder //… def book = ApplicationHolder.application.getClassForName("library.Book").findByTitle("Groovy in Action"

Doesn't it seem like this would be a normal thing to do if someone wanted to use Hibernate XML?

2

2 Answers

1
votes

You need the class definition files in src/java and the hibernate mapping files in grails-app/conf/hibernate as explained in Grails 1.0.3 Upgrade Problems.

0
votes

According to this: If GORM (Grails Object Relational Mapping) is not flexible enough for your liking you can alternatively map your domain classes using Hibernate, either via XML mapping files or JPA annotations. You will be able to map Grails domain classes onto a wider range of legacy systems and be more flexible in the creation of your database schema. Best of all, you will still be able to call all of the dynamic persistent and query methods provided by GORM!