jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.5k stars 4.02k forks source link

Issue with column name of key #19858

Closed Ebsan closed 5 months ago

Ebsan commented 2 years ago
Overview of the issue

I'm getting an error when querying a table with a column name of "key". I have postgresql chosen and it doesn't seem like "key" is a reserved word. However, if it is could it be added to the reserved word in the JDL schema? At the moment we can call a field "key" in the JDL.

Error message:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "select licenseact0_.id as id1_4_, licenseact0_.assigned as assigned2_4_, licenseact0_.[*]key as key3_4_, licenseact0_.license_bundle_id as license_5_4_, licenseact0_.special_instruction as special_4_4_ from license_activation_key licenseact0_ order by licenseact0_.id asc limit ?"; expected "identifier"; SQL statement:
select licenseact0_.id as id1_4_, licenseact0_.assigned as assigned2_4_, licenseact0_.key as key3_4_, licenseact0_.license_bundle_id as license_5_4_, licenseact0_.special_instruction as special_4_4_ from license_activation_key licenseact0_ order by licenseact0_.id asc limit ? [42001-214]
Motivation for or Use Case

If "key" is a reserved word for some supported databases than it shouldn't be allowed to be used in JDLs.

Reproduce the error
Related issues
Suggest a Fix
JHipster Version(s)

7.9.3

JHipster configuration
JHipster Version(s)
jhi-793@0.0.1-SNAPSHOT D:\Ebsan\workspace\jhi-7.9.3-test
`-- generator-jhipster@7.9.3
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "jhi793",
    "blueprints": [],
    "buildTool": "maven",
    "cacheProvider": "ehcache",
    "clientFramework": "angularX",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1664289688446,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": false,
    "entities": [
      "DownloadHistory",
      "LicenseActivationKey",
      "LicenseBundle",
      "LicenseSoftwareAssignment",
      "SoftwareCatalog",
      "SoftwareCatalogFile",
      "SwlUser"
    ],
    "entitySuffix": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.3",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1664290130000,
    "messageBroker": false,
    "microfrontend": false,
    "microfrontends": [],
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "com.mycompany.myapp",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": false,
    "serverPort": "8080",
    "serverSideOptions": [],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": [],
    "websocket": false,
    "withAdminUi": true
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity DownloadHistory {
  sid String required
  org String required
  softwareType String required
  downloadDate Instant required
}
entity LicenseActivationKey {
  key String required
  assigned Boolean required
  specialInstruction String
}
entity LicenseBundle {
  status LicenseStatus required
  licenseModel LicenseModelType required
  purchaseQuantity Integer required
  quantityMultiplier Integer required
  quantityAssigned Integer required
  parId String required
  vendorReference String required
  expirationDate LocalDate
  supportExpirationDate LocalDate
  adminNote String
}
entity LicenseSoftwareAssignment
entity SoftwareCatalog {
  manufacturer String required
  product String required
  version String required
  productDescription String
  internetUrl String required
  softwareType SoftwareType required
  publishedDate LocalDate
  accessControl String
  note String
}
entity SoftwareCatalogFile {
  location String required
  filename String required
  note String
}
entity SwlUser {
  sid String required unique maxlength(7)
  fullName String required
  currentOrg String required
  assignedOrg String
  securePhone String
  activeSwlUser Boolean required
  lastLoginDate LocalDate
  swlUserNote String
}
enum LicenseStatus {
  FRENCH,
  ENGLISH,
  SPANISH
}
enum LicenseModelType {
  FRENCH,
  ENGLISH,
  SPANISH
}
enum SoftwareType {
  FOSS,
  COTS
}

relationship OneToMany {
  SoftwareCatalog{downloadHistory} to DownloadHistory{softwareCatalog}
  SoftwareCatalogFile{downloadHistory} to DownloadHistory{softwareCatalogFile}
  LicenseBundle{licenseActivationKey} to LicenseActivationKey{licenseBundle}
  SoftwareCatalog{licenseSoftwareAssignment} to LicenseSoftwareAssignment{softwareCatalog}
  SwlUser{licenseSoftwareAssignment} to LicenseSoftwareAssignment{swlUser}
  LicenseActivationKey{licenseSoftwareAssignment} to LicenseSoftwareAssignment{licenseActivationKey}
  LicenseActivationKey{softwareCatalog} to SoftwareCatalog{licenseActivationKey}
  SoftwareCatalog{softwareCatalogFile} to SoftwareCatalogFile{softwareCatalog}
}

paginate DownloadHistory, LicenseActivationKey, LicenseBundle, LicenseSoftwareAssignment, SoftwareCatalog, SoftwareCatalogFile, SwlUser with pagination

Environment and Tools

openjdk version "11.0.10" 2021-01-19 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)

git version 2.34.1.windows.1

node: v16.16.0

npm: 8.3.0

Docker version 20.10.17, build 100c701

docker-compose version 1.29.2, build 5becea4c

No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

gmarziou commented 2 years ago

From the PostgreSQL doc, KEY is a reserved word of SQL-92. So I suppose it should be added to all databases, see https://github.com/jhipster/generator-jhipster/tree/main/jdl/jhipster/reserved-keywords

And it's the same for H2 (like in your error): http://www.h2database.com/html/advanced.html#keywords