Difference between MySQL and PostgreSQL when generating BasicType as Key

56 views
Skip to first unread message

onclez...@gmail.com

unread,
Dec 23, 2015, 4:54:56 AM12/23/15
to Sculptor Generator
Hi everybody !
I'm using Sculptor 3.0.6 and i have a strange behavior between MySQL and PostgreSQL when generating BasicType as Key.

Suppose i have a simple Person :
Entity Person {
    reference
@Ssn ssn key
........
}



And the Ssn
BasicType Ssn {
     nogap
     
String number key
     
String country key
}

With
db.product=mysql
generate.ddl=true

i have this ddl
CREATE TABLE PERSON (
    ID BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
,
    DESCRIPTION VARCHAR
(100),
    PERSONNAME BIGINT NOT NULL
,
    SSN_NUMBER VARCHAR
(100) NOT NULL,
    SSN_COUNTRY VARCHAR
(100) NOT NULL,
    GENRE VARCHAR
(5),
    CREATEDDATE DATETIME
,
    CREATEDBY VARCHAR
(50),
    LASTUPDATED DATETIME
,
    LASTUPDATEDBY VARCHAR
(50),
    VERSION BIGINT NOT NULL
,
    CONSTRAINT UNIQUE
(
        SSN_NUMBER
, SSN_COUNTRY
   
)
);
For me, it's ok

But with
db.product=postgresql
generate.ddl=true

i have this ddl

CREATE TABLE PERSON (
    ID BIGINT NOT NULL
,
    DESCRIPTION VARCHAR
(100),
   
NUMBER_NUMBER VARCHAR(100) NOT NULL,
   
COUNTRY_COUNTRY VARCHAR(100) NOT NULL,
    GENRE VARCHAR
(5),
    PERSONNAME BIGINT NOT NULL
,
    CREATEDDATE TIMESTAMP
,
    CREATEDBY VARCHAR
(50),
    LASTUPDATED TIMESTAMP
,
    LASTUPDATEDBY VARCHAR
(50),
    VERSION BIGINT NOT NULL
);

ALTER TABLE PERSON
    ADD CONSTRAINT UQ_PERSON UNIQUE
(SSN_NUMBER, SSN_COUNTRY);

The alter table not match the creation table declaration and an error is trigged for Postgre !!
In the table -> attrName_attrName -> wrong
In the alter table -> entityName_attrName -> right

So in which template can i modify this behavior ? Or is there an other way to resolve this error !

Thx a lot !

Torsten Juergeleit

unread,
Jan 9, 2016, 7:16:11 AM1/9/16
to Sculptor Generator
This issue in OracleDDLTmpl is fixed in #183.

/Torsten

onclez...@gmail.com

unread,
Jan 12, 2016, 5:17:57 AM1/12/16
to Sculptor Generator

Thx for reply Torsten!

So here what i‘ve done :

-           Extends Sculptor by overriding OracleDDLTmpl

@ChainOverride

class OracleDDLTmplOverride extends OracleDDLTmpl {

     @Inject extension DbHelper dbHelper

     @Inject extension PropertiesBase propertiesBase

     @Inject extension Helper helper

    

 

override def String containedColumns(Reference it, String prefix, boolean parentIsNullable) {

     val rows = new StringBuilder()

     rows.append(it.to.attributes.filter[a | !a.transient].map[a | ",\n\t" + column(a, getDatabaseName(prefix, it), parentIsNullable || nullable)].join)

     rows.append(it.to.references.filter[r | !r.transient && r.to instanceof Enum].map[r | ",\n\t" + enumColumn(r, getDatabaseName(prefix, it), parentIsNullable || nullable)].join)

     rows.append(it.to.references.filter[r | !r.transient && r.to instanceof BasicType].map[b | containedColumns(b, getDatabaseName(it), parentIsNullable || nullable)].join)     

     if (rows.length < 3)

              ""

     else

              rows.substring(3)

}

 

}

                I have others extended methods in OracleDDLTmplOverride that work well.


-          Adding this project as a dependency of the build :

<plugin>

            <groupId>org.sculptorgenerator</groupId>

            <artifactId>sculptor-maven-plugin</artifactId>

            <version>${sculptor.version}</version>

            <configuration>

                        <verbose>false</verbose>

            </configuration>

            <executions>

                        <execution>

                                   <id>cleanup</id>

                                   <goals>

                                               <goal>clean</goal>

                                   </goals>

                        </execution>

                        <execution>

                                   <id>code-generation</id>

                                   <goals>

                                               <goal>generate</goal>

                                   </goals>

                        </execution>

                        <execution>

                                   <id>image-generation</id>

                                   <goals>

                                               <goal>generate-images</goal>

                                   </goals>

                        </execution>

            </executions>

            <dependencies>

                        <dependency>

                                   <groupId>my.sculptor</groupId>

                                   <artifactId>ProjectSculptor-generator</artifactId>

                                   <version>1.0.0</version>

                        </dependency>

            </dependencies>

</plugin>

 

-          In my sculptor-generator.properties

db.product=postgresql

generate.ddl=true

 

 

I have the same result !! Am I wrong ??

Regards

onclez...@gmail.com

unread,
Jan 12, 2016, 5:33:13 AM1/12/16
to Sculptor Generator

           
<groupId>my.toolkit</groupId>
           
<artifactId>ProjectSculptor-generator</artifactId>
           
<version>2.0.0</version>
       
</dependency>
   
</dependencies>
</plugin>



-    In my sculptor-generator.properties
db.product=postgresql
generate
.ddl=true


I have the same result !! Am I wrong ??
Regards


Le mercredi 23 décembre 2015 10:54:56 UTC+1, onclez...@gmail.com a écrit :

Torsten Juergeleit

unread,
Jan 13, 2016, 8:53:15 AM1/13/16
to Sculptor Generator
Are you sure that the method overriding method from "OracleDDLTmplOverride.containedColumns()" is executed and not the original one? You can check by throwing an excepetion in this method.

Regarding your Person/Ssn sample the important line from the overridden template method "OracleDDLTmpl.containedColumns()" is the one with the "instanceof Basictype" check. In this line the method "containedColumns()" is called recursively.

/Torsten

onclez...@gmail.com

unread,
Jan 22, 2016, 8:01:21 AM1/22/16
to Sculptor Generator
Hi Torsten,

It's ok now.

BTW, i was able to migrate from 3.0.6 to 3.1.0 : good !
Except for the charset : before, every thing was in UTF-8 (project.build.sourceEncoding). Some documentations in models were with é, è à or ê. No problems on Eclipse but in Jenkins....
So i change it to ISO-8859-1, and it's ok. The Sculptor maven plugin can't be set to use UTF-8...?

Thx



Le mercredi 23 décembre 2015 10:54:56 UTC+1, onclez...@gmail.com a écrit :

Torsten Juergeleit

unread,
Jan 24, 2016, 12:25:47 PM1/24/16
to Sculptor Generator
So i change it to ISO-8859-1, and it's ok. The Sculptor maven plugin can't be set to use UTF-8...?

You can use either encoding. But you have to be consistent in Eclipse and Maven. Switching the encoding inconsistently gets the guillemets characters in the Xtend templates corrupted.

/Torsten
Reply all
Reply to author
Forward
0 new messages