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

Roo should support selection of user-supplied JPA @GenerationType value

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: PERSISTENCE
    • Labels:
      None
    • Environment:
      all

      Description

      When using an identifier of type String our tests will not start up using DBUnit (using hibernate provider).. those tables that have an identifier of String are not loaded by Hibernate for DBUnit; most likely will happen beyond testing but didn't get that far.

      I have done a nasty wee hack that will check for a couple of new RooEntity annotation attributes that allow one to set the strategy and the generator (we also have another requirement to have our own generator).

      Added to RooEntity:

          String generatedValueGenerator() default "";
          String generatedValueStrategy() default "";
      
      Add to EntityMetadata to getIdentifierField - this is NOT so tidy :-):
      
              // Compute the column name, as required
              if ("NULL".equalsIgnoreCase(this.generatedValueStrategy))
              {
              }
              else if ("IDENTITY".equalsIgnoreCase(this.generatedValueStrategy))
              {
                  List<AnnotationAttributeValue<?>> generatedValueAttributes = new ArrayList<AnnotationAttributeValue<?>>();
                  generatedValueAttributes.add(new EnumAttributeValue(new JavaSymbolName("strategy"), new EnumDetails(new JavaType("javax.persistence.GenerationType"), new JavaSymbolName("IDENTITY"))));
                  AnnotationMetadata generatedValueAnnotation = new DefaultAnnotationMetadata(new JavaType("javax.persistence.GeneratedValue"), generatedValueAttributes);
                  annotations.add(generatedValueAnnotation);
              }
              else
              {
                  List<AnnotationAttributeValue<?>> generatedValueAttributes = new ArrayList<AnnotationAttributeValue<?>>();
      
                  // add a generator to javax.persistence.GeneratedValue
                  if(!"".equals(this.generatedValueGenerator))
                  {
                      generatedValueAttributes.add(new StringAttributeValue(new JavaSymbolName("generator"), this.generatedValueGenerator));
      
      //                generatedValueAttributes.add(new EnumAttributeValue(new JavaSymbolName("generator"), new EnumDetails(new JavaType("javax.persistence.GenerationType"), new JavaSymbolName("AUTO"))));
      
                      List<AnnotationAttributeValue<?>> genericGeneratorAttributes = new ArrayList<AnnotationAttributeValue<?>>();
      //                genericGeneratorAttributes.add(new EnumAttributeValue(new JavaSymbolName("strategy"), new EnumDetails(new JavaType("javax.persistence.GenerationType"), new JavaSymbolName("AUTO"))));
                      genericGeneratorAttributes.add(new StringAttributeValue(new JavaSymbolName("strategy"), this.generatedValueGenerator));
                      genericGeneratorAttributes.add(new StringAttributeValue(new JavaSymbolName("name"), this.generatedValueGenerator));
      //                @GenericGenerator(name = "IdGenerator", strategy = "IdGenerator")
                              
                      AnnotationMetadata genericGeneratorAttributesAnnotation = new DefaultAnnotationMetadata(new JavaType("org.hibernate.annotations.GenericGenerator"), genericGeneratorAttributes);
                      annotations.add(genericGeneratorAttributesAnnotation);      
                  }
                  else
                  {
                      generatedValueAttributes.add(new EnumAttributeValue(new JavaSymbolName("strategy"), new EnumDetails(new JavaType("javax.persistence.GenerationType"), new JavaSymbolName("AUTO"))));
                  }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                stewarta Alan Stewart
                Reporter:
                kermiedefrog Kermie de Frog
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: