Search code examples
spring-roo

Mapping & Scaffolding Many-to-Many Relation with extra column - Spring Roo


I'm trying to mapping and scaffolding many-to-many relation with Spring Roo.

For example, I have two column: Product and Order with the many-to-many relationship.

So I need to create an intermediate table such as ProductOrder, with some extra column, for example, OrderDate.

So my mapping class will look like this:

...
@RooJpaActiveRecord(identifierType = **ProductOrderId**.class)
public class ProductOrder {
    private Date OrderDate;
}

The ProductOrderId class will look like this:

...
@RooIdentifier
public final class ProductOrderId implements Serializable {

    @ManyToOne
    private Product product_id;

    @ManyToOne
    private Order order_id;

}

After that, I ran this command in Roo Shell to scaffolding views:

web mvc scaffold --class ...

But the scaffolded views just show two text fields for Order Id and Product Id, it should show a Combobox which I can select and it cannot insert to the database.

I've searched for a while on the internet, but seem likes there is no solution.

Is there any workaround for this problem?


Solution

  • I suggest you use the new Spring Roo 2.0.0.M3, it solves a lot of problems related to entity relationships.

    In your case, now the Select2 component is used to select the related entity.

    Visit the project page at http://projects.spring.io/spring-roo/ to download it.

    Note that a Milestone version generate artifacts that could change in newer versions, but it could affect your project or not depending on your needs.

    May the Force be with you.