Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Does Roo support n:m mappings ?

  1. #11

    Default

    Maybe 'id' and 'description' are reserved words?

  2. #12
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    Yes you are on the right track. Your UserRole type uses a field named 'id' as part of the type definition. This field name is also the field name Roo chooses by default as a JPA @Id. Therefore, you see that the updates to UserRole are handled different to what you would normally expect. You have two choices to address this issue:

    1. Rename your id field to something other than id (ie roleId). This way Roo will still choose id as the identifier for persistence purposes and roleId becomes independent of that.

    2. Change the default name of the identifier in your UserRole type:

    Code:
    @RooEntity(identifierField="persistenceId")  
    public class UserRole{...}
    This way you can retain your 'id' field name and instruct Roo to use the 'persistenceId' (or any other name) field for its internal JPA purposes.

    If you use any of these options your application should work fine.

    HTH
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  3. #13

    Default

    Hi Stefen,

    I have been trying previous code and it was not working for me. Did some changes and now I can see both side of the many-to-many updated

    Code:
    project --topLevelPackage com.foo.opensource
    persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
    
    entity --class ~.domain.Community --testAutomatically
    field string name 
    entity --class ~.domain.Person --testAutomatically
    field string name 
    field set --fieldName communities --element ~.domain.Community --cardinality MANY_TO_MANY
    field set --fieldName members         --element ~.domain.Person       --class ~.domain.Community --cardinality MANY_TO_MANY --mappedBy communities
    controller all --package ~.web
    Missing part being --mappedBy communities

    Unfortunately, I can only add communities to poeple and not the opposite from the UI. Still something missing

    --Marc

  4. #14

    Default

    After looking at hibernate doc here: http://docs.jboss.org/hibernate/core...-bidirectional

    found that "Changes made only to the inverse end of the association are not persisted."

    so that explains why I can't add items from both sides of the association.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •