Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-1504

Remove unneeded targetEntity and @JoinColumn from @ManyToOne and @OneToOne

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 1.1.0.M1, 1.1.0.M2, 1.1.0.M3
    • Fix Version/s: 1.1.0.RC1
    • Component/s: PERSISTENCE
    • Labels:
      None

      Description

      According to the JPA documentation for targetEntity:

      (Optional) The entity class that is the target of the association.
      Defaults to the type of the field or property that stores the association.

      Therefore, putting target entity in every definition serves no purpose and is implied.

      Also, the empty @JoinColumn serves no purpose.

      So the following pieces of code are equivalent and work exactly the same:

      Generated:

      @Entity
      @RooJavaBean
      @RooToString
      @RooEntity
      public class Pet {
      
          @NotNull
          private String name;
      
          @ManyToOne(targetEntity = Owner.class)
          @JoinColumn
          private Owner owner;
      }
      

      Desired:

      @Entity
      @RooJavaBean
      @RooToString
      @RooEntity
      public class Pet {
      
          @NotNull
          private String name;
      
          @ManyToOne
          private Owner owner;
      }
      

      Roo script:

      project --topLevelPackage com.pet
      persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY 
      entity --class ~.Owner
      field string --fieldName name --notNull 
      entity --class ~.Pet
      field string --fieldName name --notNull 
      field reference --fieldName owner --type ~.Owner
      controller scaffold --class ~.web.PetController
      field set --class ~.Owner --fieldName pets --element ~.Pet --cardinality ONE_TO_MANY --mappedBy owner
      controller scaffold --class ~.web.OwnerController
      

        Attachments

          Activity

            People

            Assignee:
            stewarta Alan Stewart
            Reporter:
            sdmurphy Scott Murphy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: