2
votes

My system consists of a back-end part, written in Java, exposing a set of web services which are defined contract-first using WSDL and XSD. Among the data transported over the web services are a large set of product types (they are different kinds of bank accounts, to be precise). Our front-end is a Grails web application. It uses and exposes the data and operations hosted by the back-end. The front-end has no database on its own for security reasons; all data is stored on the back-end. Pretty standard architecture.

Now, the set of products is large, growing, and volatile. Each product type has to be CRUD-ed on the web application user interface. It would be lovely if I could tell Grails to use the XSD specifications of the product types as domain types, and generate views and controllers for them.

I have not found a solution for this puzzle yet, even after extensive experiments and lots of web browsing. I have about a year's worth of professional experience with Grails. Any help or ideas would be appreciated.

Some details:

A product type is a simple POJO data carrier. Some simplified examples:

package jaxbgenerated;

public class Product1 {
    protected Account from;
    protected Account to;
    protected String name;
    // + getters and setters
}

public class Product2 {
    protected List<Account> accounts;
    protected String name;
    // + getters and setters
}

public class Account {
    protected String id1;
    protected String id2;
    // + getters and setters
}

Note that "Account" is not a product type but it is a JAXB-generated type. Products can contain such in addition to properties of simple data types like String, int and Date but they never contain other product types.

The end result I am aiming for is a Grails-generated form where a user can edit a Product1 instance with nested forms for editing its constituent Accounts. And likewise for Product2.

My idea is to first manually code a Grails domain class for each JAXB-generated type:

//in grails-app/domain:
 
import utilities.Copier
 
class Product1 extends jaxbgenerated.Product1 {
    Product1(jaxbgenerated.Product1 jaxb) {
        Copier.copy(jaxb, this)
    }

    static constraints = {
    }
}

There is a bit of boilerplate code here but nothing more than I can live with. The Copier.copy() function is (I think) needed to convert a jaxbegenerated.Product instance fetched from the back-end to a Product1 instance which can be used in Grails. It recursively looks for jaxbgenerated properties in the jaxb source, and copies their values to the corresponding Grails domain type. The constructor is invoked from a layer that fetches data from the back-end.

I can use the constraints block to manually add semantic constraints where needed, e.g. that the "from" and "to" accounts are not the same.

Next, I generate controllers and views for all the Grails domain classes thus constructed, and run the application. And get a stack of exceptions:

Caused by MappingException: Could not determine type for: Account, at table:
product1_type, for columns: [org.hibernate.mapping.Column(from)]

I think the trouble here is that Product1's "from" and "to" properties are not of type Account but of type jaxbgenerated.Account.

I have tried different approaches but to no avail. Some notes:

  1. As I said, all data storage happens on my back-end, so I do not need the GORM/Hibernate aspect of Grails. Therefore I tried adding "static mapWith = "none" to the domain classes but that did not help.
  2. I tried explicitly telling Hibernate the type of the Accounts in Product1 by adding "static mapping = { from type: Account }" but that did not work either.

Any help or ideas would be appreciated.

/Jan Reher, Systematic A/S, Denmark

1

1 Answers

0
votes

I think you have do write a dababase plugin similar in concept to this simpledb