0
votes

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
        }
    }
}
2
Don't you want to do it Grails way? Use Domain classes? - Mr. Cat
It's not an option for this project unfortunately. The classes I need to use are shared with other java applications. - arcdegree

2 Answers

0
votes

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

The data binding function is not trying to bind referencedPropertyType. The binder is trying to retrieve that value because the value helps the data binder figure out which types of objects need to be created during data binding.

It looks like there may be a bug with respect to Java domain models in certain circumstances when using the Hibernate plugin. If you file a bug report at https://jira.grails.org/browse/GRAILS and attach a simple sample app, we will get it straightened out.

Sorry for the trouble.

0
votes

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.