Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify in id if we want it autoGenerated #14108

Closed
1 task done
yelhouti opened this issue Mar 1, 2021 · 12 comments
Closed
1 task done

Allow to specify in id if we want it autoGenerated #14108

yelhouti opened this issue Mar 1, 2021 · 12 comments

Comments

@yelhouti
Copy link
Contributor

yelhouti commented Mar 1, 2021

Overview of the feature request

The generator infers if an @Id should be autoGenerated bases on the field type.

Motivation for or Use Case

This prevents from having the ability of adding a UUID generated in the frontend or a Long added manually based on a manual process (from other software...)

  • Checking this box is mandatory (this is just to show you read everything)
@filyasse
Copy link

filyasse commented Mar 1, 2021

Auto generating the id is the default behavior in the Spring Data entity.

to add Ids manually just remove the annotation @GeneratedValue(strategy = GenerationType.IDENTITY) from the id attribute in your domain class. and remove the code below from your RestController.

if (entityName.getId() != null) {throw new BadRequestAlertException("A new enitytName cannot already have an ID", ENTITY_NAME, "idexists"); }

Because changing this is simple (could be done manually or with refactoring) and seeing this in the generator will cause confusion,; I don't think this option should be added.

Regards,

@gmarziou
Copy link
Contributor

gmarziou commented Mar 1, 2021

@king-il this does not look as simple to me. For instance, this has impacts on client code too.
Also, it does not need to be seen in generator questions, it could be a JDL option only.

@yelhouti how would you want to implement it in client? Should the id value be entered by user? If it's a UUID, should a random value be generated?

@yelhouti
Copy link
Contributor Author

yelhouti commented Mar 1, 2021

thanks @gmarziou and indeed, changes needs to be added in liquibase frontend e2e tests... but than fully, we already have a variable field.autoGenerate that is used for String ids... (not working correctly in current version by the way) and would use that same variable to make the UUID generation. I would generate the UUID in the client to allow for easier coding of offline mode...

@mraible
Copy link
Contributor

mraible commented Mar 1, 2021

I don't think we should generate UUID's in the client because then every client implementation needs to worry about it.

@yelhouti
Copy link
Contributor Author

yelhouti commented Mar 1, 2021

@mraible this is totally optional and could be left to blueprints, for the frontend. Without this, an offline mode is much harder to implement because of relationships...

@filyasse
Copy link

filyasse commented Mar 1, 2021

@yelhouti @gmarziou if the id is of type Long no other changes are needed except for making the id field visible (by default hidden) in the frontend then you could use any third party generators or enter it manually.

and i think that jhipster don't allow UUID or String as pk in the JDL.
so the question here is to support custom ids in the jdl since the id field is being handled automatically.

===========================================================
the other solution is to add a uuid field in your enity beside the auto-generated id and add type validations.

@yelhouti
Copy link
Contributor Author

yelhouti commented Mar 1, 2021

@king-il the not yet release v7 allows it, I implemented the @id annotation in JHipster (it allows String, + UUID was added later by someone else probably mshima), the other 2 people are core team members, we all spent many hours inside the code and know what we are talking about ;) .

@filyasse
Copy link

filyasse commented Mar 1, 2021

@yelhouti i didn't know the beta version allows it. I'm only using the current stable version and i thought you were talking about it.
anyway good luck :)

@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2021

This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days

@yelhouti
Copy link
Contributor Author

yelhouti commented Apr 3, 2021

I am willing to make a PR if more people are interested, for now I might just do it manually.

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2021

This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days

@pascalgrimaud pascalgrimaud added this to the 7.1.0 milestone May 28, 2021
@pascalgrimaud pascalgrimaud reopened this Jan 11, 2022
@DanielFran
Copy link
Member

Close by #17837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants