Uploaded image for project: 'Tools (JBoss Tools)'
  1. Tools (JBoss Tools)
  2. JBIDE-12637

Hibernate Tools generates @SequenceGenerator with not unique name

XMLWordPrintable

    • devex #115 May 2016
    • 8
    • Hide

      Generates entities with EJB3 annotations with Reverse Engineering Strategy :

      DeletagatingReverseEngineeringStrategy .java
         
      @Override
      public Properties getTableIdentifierProperties(TableIdentifier dentifier)      {
       Properties properties = new Properties();
       properties.put("sequence", "S_"+identifier.getName());
       return properties;
      }
        
      public String getTableIdentifierStrategyName(TableIdentifier identifier) {
       return "sequence";
      }
      
      Show
      Generates entities with EJB3 annotations with Reverse Engineering Strategy : DeletagatingReverseEngineeringStrategy .java @Override public Properties getTableIdentifierProperties(TableIdentifier dentifier) { Properties properties = new Properties(); properties.put( "sequence" , "S_" +identifier.getName()); return properties; } public String getTableIdentifierStrategyName(TableIdentifier identifier) { return "sequence" ; }

      When generating entities with EJB3 annotations with a strategy set to "sequence", Hibernate tools generates POJOs with non unique javax.persistence.SequenceGenerator name "generator". But according to the Java documentation :

      String name (Required) A unique generator name that can be referenced by one or more classes to be the generator for primary key values.

      See javadoc

      Exemple of generated code with 4.0.0 Alpha1:

      @SequenceGenerator(name = "generator", sequenceName = "S_CLIENT")
         @Id
         @GeneratedValue(strategy = SEQUENCE, generator = "generator")
         @Column(name = "CLIENT_ID", unique = true, nullable = false, precision = 22, scale = 0)
         public long getClientId() {
            return this.clientId;
         }
      

      Source code can be seen here.
      So looks like the //TODO comment is right and it should generate a unique name atribute. sequencename+"generator" would be a good name.
      It would even be better if we could define this name in reveng.xml or/and in a DelegatingReverseEngineeringStrategy class.

              kaers@redhat.com Koen Aers
              nicotexas Nicolas Bihan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: