Overview of the issue
Hi guys, I'm working on the support of composite primary keys in jhipster. the goal is to allow use cases where we for complex table relationships...
This thread will help follow advancement of the work and discuss design choices that need to be made.
I'll try to put different questions here, and discuss them in the comments:
- How to specify primary keys in the entity.json
- How to handle urls: GET /id1/id2/id3, vs /id1-id2-id3 ...
- How to handle Create vs Update (the keys is always specified since there is no AUTOINCREMENT...)
Motivation for or Use Case
When we want a many to many relationship with additional fields or more than two tables we need a lot of boiler plate code.
Reproduce the error
Related issues
Suggest a Fix
JHipster Version(s)
Environment and Tools
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
git version 2.14.3 (Apple Git-98)
node: v6.10.3
npm: 5.6.0
bower: 1.7.7
yeoman: 2.0.0
Docker version 17.12.0-ce, build c97c6d6
docker-compose version 1.18.0, build 8dd22a9
4.14
JHipster configuration
JHipster configuration, a .yo-rc.json
file generated in the root folder
.yo-rc.json file
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.xxx.yyy.zzz",
"nativeLanguage": "en"
},
"jhipsterVersion": "4.14.0",
"baseName": "zzz",
"packageName": "com.xxx.yyy.zzz",
"packageFolder": "com/xxx/yyy/zzz",
"serverPort": "8081",
"authenticationType": "oauth2",
"cacheProvider": "hazelcast",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": "eureka",
"buildTool": "gradle",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"jwtSecretKey": "replaced-by-jhipster-info",
"enableTranslation": true,
"applicationType": "microservice",
"testFrameworks": [],
"jhiPrefix": "jhi",
"nativeLanguage": "en",
"languages": [
"en",
"fr"
],
"clientPackageManager": "npm",
"skipClient": true,
"skipUserManagement": true
}
}
Entity configuration(s) entityName.json
files generated in the .jhipster
directory
I propose to add something like this in normal json file, I will also modify the example as the discution go further:
{
"fluentMethods": true,
"relationships": [
{
"relationshipType": "many-to-one",
"relationshipValidateRules": "required",
"relationshipName": "business",
"otherEntityName": "business",
"otherEntityField": "name"
},
{
"relationshipType": "many-to-one",
"relationshipValidateRules": "required",
"relationshipName": "basicIndex",
"otherEntityName": "basicIndex",
"otherEntityField": "name"
}
],
"fields": [
{
"fieldName": "year",
"fieldType": "Integer",
"fieldValidateRules": [
"required"
]
},
{
"fieldName": "month",
"fieldType": "Integer",
"fieldValidateRules": [
"min",
"max"
],
"fieldValidateRulesMin": 1,
"fieldValidateRulesMax": 12
},
{
"fieldName": "value",
"fieldType": "Integer",
"fieldValidateRules": [
"required",
"min"
],
"fieldValidateRulesMin": 0
}
],
"id": [
{
"attributeName": "businessId",
"columnName": "business_id"
},
{
"attributeName": "basicIndexId",
"columnName": "basic_index_id"
},
{
"attributeName": "year",
"columnName": "year"
}
],
"changelogDate": "20180210195726",
"entityTableName": "business_basic_index",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceImpl",
"jpaMetamodelFiltering": true,
"microserviceName": "businessman"
}
This is clearly related to JDL, but JDL support will be added later and will depend on the new entity.json format
Browsers and Operating System
OSx and not relevant
- [x] Checking this box is mandatory (this is just to show you read everything)
Example repo for what the result should be, all suggestions are welcome:
https://github.com/yelhouti/jhipster-composite-key
area: feature request :bulb: theme: JDL $$ bug-bounty $$ $500 theme: database