views:

51

answers:

1

I'm trying to use Spring Roo to generate entities with a @OneToMany unidirectional relationship. Here's what I've tried:

entity --class ~.family.Child
field string --fieldName name
controller scaffold ~.web.ChildController
entity --class ~.family.Father
field string --fieldName name
field set --fieldName children --element ~.family.Child --cardinality ONE_TO_MANY 
controller scaffold ~.web.FatherController
perform package

This produces the expected entities and database tables (including a link table.) The Father entity is generated with the following annotation, which conforms to the JPA spec:

@OneToMany(cascade = CascadeType.ALL)
private Set<family.Child> message = new java.util.HashSet<family.Child>();

But when I go to the Roo-generated admin page, and click Create Father, I find the following message:

Create Father

Name:      (field to enter name)
Children:  This relationship is managed from the Father side.

This looks like a bug in Roo. Has anyone found a work-around? Or do I have an error in here?

+1  A: 

OK, here's a workaround: In the fathers/create.jspx file, Roo generates the following line:

<field:simple field="children" id="c:family.Father.children" messageCode="entity.reference.not.managed" 
 messageCodeAttribute="Child" z="dMKrUOiCeYNub4vNayuiWJ99s1k="/>

This should be replaced by:

<field:select field="children" id="c:family.Father.children" itemValue="id" 
 items="${children}" multiple="true" path="/children"/>

And it should work.

FarmBoy
thanks..I myself was trying it..but it was not working..I looked into spring roo jira but didn't find any bug for it..
Shekhar
Glad to be able to help.
FarmBoy