Spring Roo Addon and self referencing entities

Spring Roo Addon v1.0.0 does not allow using elf referencing entities

Roo Commands


project --topLevelPackage vroo
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
entity --class ~.domain.Self
field string --fieldName descp --notNull --sizeMax 20
field reference --fieldName parent --type ~.domain.Self
vaadin setup --applicationPackage ~.web --baseName vroo --themeName vroo --useJpaContainer false
vaadin generate all --package ~.web.ui --visuallyComposable true 

The Compilation Error


# mvn install
[INFO]
 Scanning for projects...
[INFO]
                                                                         
[INFO]
 ------------------------------------------------------------------------
[INFO]
 Building vroo 0.1.0.BUILD-SNAPSHOT
[INFO]
 ------------------------------------------------------------------------
[INFO]
 
[INFO]
 --- maven-clean-plugin:2.4.1:clean (default-clean) @ vroo ---
[INFO]
 
[INFO]
 --- aspectj-maven-plugin:1.2:compile (default) @ vroo ---
[WARNING]
 this affected type is not exposed to the weaver: com.vaadin.data.util.AbstractBeanContainer (needed for privileged access) [Xlint:typeNotExposedToWeaver]

[ERROR]
 The method getSelfCaptionPropertyId() is undefined for the type SelfView
[ERROR]
 The method getContainerForSelves() is undefined for the type SelfForm
[ERROR]
 The method getSelfCaptionPropertyId() is undefined for the type SelfForm
[WARNING]
 advice defined in org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect has not been applied [Xlint:adviceDidNotMatch]

[WARNING]
 advice defined in org.springframework.scheduling.aspectj.AbstractAsyncExecutionAspect has not been applied [Xlint:adviceDidNotMatch]

[WARNING]
 advice defined in org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl has not been applied [Xlint:adviceDidNotMatch]

[WARNING]
 advice defined in org.springframework.mock.staticmock.AbstractMethodMockingControl has not been applied [Xlint:adviceDidNotMatch]

[WARNING]
 advice defined in org.springframework.mock.staticmock.AbstractMethodMockingControl has not been applied [Xlint:adviceDidNotMatch]

[INFO]
 ------------------------------------------------------------------------
[INFO]
 BUILD FAILURE
[INFO]
 ------------------------------------------------------------------------
[INFO]
 Total time: 5.645s
[INFO]
 Finished at: Thu Aug 11 15:44:14 WEST 2011
[INFO]
 Final Memory: 9M/172M
[INFO]
 ------------------------------------------------------------------------

Whou to solve this?

This is an important question, we’re having the exact same problem.

Did anyone make self-referencing entities work in Vaadin?

Thanks!

A Workadound


In file SelfForm.java add the imports

import vroo.domain.Self;
import com.vaadin.data.util.BeanContainer;


Again in file SelfForm.java add

    @AutoGenerated
    private ComboBox parentField;

    public Object getSelfCaptionPropertyId() {
        return "descp";
    }

    private BeanContainer<Long, Self> containerForSelves;

    public BeanContainer<Long, Self> getContainerForSelves() {
        BeanContainer<Long, Self> container = new BeanContainer<Long, Self>(Self.class);
        container.setBeanIdProperty("id");
        for (Self entity : Self.findAllSelves()) {
            container.addBean(entity);
        }
        return container;
    }


Continuing in SelfForm.java add to buildFieldLayout method:


    private VerticalLayout buildFieldLayout() {
        ...
        // parentField
        parentField = new ComboBox();
        parentField.setWidth("-1px");
        parentField.setHeight("-1px");
        parentField.setCaption("Parent");
        parentField.setImmediate(true);
        fieldLayout.addComponent(parentField);
        ...
    }


In SelfView.java, add


public String getSelfCaptionPropertyId() {
  return "descp";
}


Finally

We should open roo shell, and let roo generate the need code.


Using JPA Container

Similiar procedures when using cdode generated with JPA Container (vaadin option “–useJpaContainer true”, with different implementations for getContainerForSelfs