Search code examples
grailsgrails-domain-classgrails-controller

Autobinding Java Classes in Grails Fails


I've got a Grails (2.3.8) project that's integrating with a few Java classes. When I attempt to dataBind a one to many relationship, I receive the following error:

{
  "errors": 
  [
    {
      "object": "com.sample.Author",
      "message": "No such field: referencedPropertyType for class: org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateDomainClassProperty"
    }
  ]
}

Does anyone know why the data binding function is trying to bind "referencePropertyType"?

I've included a simplified version of my project with an Author and Books added to the src/java folder.

Author.java

@Entity
public class Author {

    private long _id;
    private List<Books> _books;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
    public List<Book> getBooks() {
        return _books;
    }

    // getters and setters

}

Book.java

@Entity
public class Book {

    private long _id;
    private Author author;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "AUTHOR_ID", foreignKey = @ForeignKey(name = "author_fk"), nullable = false)
    public Author getAuthor() {
        return _author;
    }

    // getters and setters

}

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping class="com.sample.Author" />
        <mapping class="com.sample.Book" />
    </session-factory>

</hibernate-configuration>

AuthorController.groovy

class AuthorController {

    def doSomething() {
        def authorInstance = new Author(params)

        if(authorInstance.hasErrors()) {
            println authorInstance.errors as JSON
        }
    }
}

Solution

  • After upgrading my project from 2.3.8 to 2.4.0 the issue has been resolved. Looks like it was a bug, but upgrading the project fixed the issue.