2
votes

I have a Grails project that uses Hibernate XML with domain classes in the src/groovy folder. I am upgrading from 1.0.3 to 1.3.7. The Hibernate XML has custom column names for some properties and the domain classes use those properties. However, when I run the application it generates new columns for the properties as if they didn't have a column property:

XML for User:

    <class name="User" table="x_users">
        <cache usage="read-write"/>
        <comment>User</comment>
...
<property name="emailAddress" column="emailAddress"/>
...
</class>

</hibernate-mapping>

Domain for User (in src/groovy):

package com.x.domain

class User {
...
  String emailAddress
...
}

This results in the column email_address being created upon running the applications. Any ideas?

UPDATE:

Even if I add mappings to the domain class, it STILL creates the new column:

class User {
    static mapping = {
        emailAddress column:'emailAddress'
        }
}
3

3 Answers

1
votes

You can cusomize the column name in the domain class itself, e.g.

class User {
  String emailAddress

  static mapping = {
    emailAddress column: "emailAddress"        
  }
}
0
votes

It looks like you cannot specify a capital letter in Hibernate 3 XML for Grails. When I change the mapping to:

 <class name="User" table="x_users">
        <cache usage="read-write"/>
        <comment>User</comment>
...
<property name="emailAddress" column="test"/>
...
</class>

it works correctly. When I change it to anything lowercase it works correctly, but introducing the capital causes it to go with the default value.

0
votes

@skaz: I think you had better put your domain class into grails-app/domain folder. The folder src/groovy is for non-persistent domain class (that will not get saved in database), so that it won't get grails mapping way. That's also the reason why Don's method didn't work.

In my experience, the porting will not be too hard. After that you can drop the hibernate config and only use grails ORM mapping (as Don point out).