-
-
Notifications
You must be signed in to change notification settings - Fork 116
Adding commands for unique constraints #18
Comments
No we dont support that. Inly required validation for relationship as of
|
Yeah... Thanks man! Le 17 mai 2016 03:51:21 GMT+02:00, Deepu K Sasidharan notifications@github.com a écrit :
Mathieu ABOU-AICHI |
@deepu105 "Having unique validation is very tricky and troublesome" Why do you say that? |
To really validate something is unique before saving it you need to compare it against existing items to determine if unique which is costly and tricky operation. If you have a simpler way to do it you are welcome to suggest |
Sorry for getting back on this so late, but Robert Mikes' question got me back here - I also don't really understand this, because what I mean is, that I would like to add the "@column(unique=true)" JPA annotation parameter to tell the DB to add a unique constraint. I don't want anything to be validated. |
The @column(unique=true) just changes the JPA/Hibernate schema generation, which JHipster doesn't use, as we relay on Liquibase scripts to create the db. |
Well, ok, true, didn't think about this, but why not add the uniqueConstraint to the liquibase generation script then? I guess, you agree, that in some cases it is necessary to make sure on DB side, that a unique constraint is a final assurance to not have duplication, but we cannot generate that with JHipster JDL. |
Yes, that's what I was thinking, to add a "unique" validation much like "required", which would just add the constraint for that column to the liquibase change log. This would not handle multi-column unique constraints, for those we would need a separate constraint definition, at the same level as entity and relationship, similarly to how it can be done in liquibase. But I wouldn't worry about multi-column for now. |
@MathieuAA Fine, then let's continue the discussion here.
but that only works for single-field unique constraints. For multi-field unique constraints, where a value-pair is supposed to be unique, we need the additional syntax. For example in a many-to-many relationship, in the relationship table we need to make sure that the same key-pair is not defined twice. @deepu105 The unique constraint created by liquibase in the database will validate the values when saving, no need to do an additional select. Unique constraints are very important to ensure that there's no duplication. For example, cannot have two users with the same username. |
@taurus227 point taken |
If you want to add a simple unique like required then its fine but then it would be nice if someone can PR it to the generator first as we clearly don't have the time at the moment |
@deepu105 that's the point =) @taurus227 is working on it. |
Any update on this? can we now use the unique? Thanks. |
As soon as I have time to do it, I'll do it. It will likely be today or this week-end. |
What I'm about to do: create a branch with the necessary code to support the |
Maybe PK will also be something useful. |
I just love expressing the domain data model in JDL. However, whenever there is a change, I find myself manually editing the server code plus regenerating the client and test code with jhipster-uml, because there is manual changes necessary in the domain code like unique constraints, advanced validation constraints etc.
Wouldn't it be nice to have the ability to generate unique constraints by expressing them via JDL? Or am I missing something?
for example:
unique { <entity>{<column_list>} }
example:
unique { A{columnA, columnB} }
to define a unique constraint on entity A with columns columnA and columnB.
The text was updated successfully, but these errors were encountered: