如何在JDL-Studio中为2列创建唯一约束? [英] How to create unique constraint for 2 columns in JDL-Studio?
问题描述
我具有以下实体配置:
entity AirplaneModelSeat {
id Long,
seatNo String required
}
relationship ManyToOne {
AirplaneModelSeat{modelId(model)} to AirplaneModel
}
此实体配置创建了这样一个表:
This entity configuration creates such a table:
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| seat_no | varchar(255) | NO | | NULL | |
| model_id_id | bigint(20) | YES | MUL | NULL | |
+-------------+--------------+------+-----+---------+----------------+
如何在JDL-Studio中为(seat_no,model_id_id)列组合应用唯一约束?
How can I apply unique constraint for (seat_no, model_id_id) column combination in JDL-Studio?
如果在JDL-Studioi中无法做到这一点,还有其他方法可以做到吗?
If this is not possible in JDL-Studioi is there any other to accomplish this?
推荐答案
据我所知,约束不是一般情况下JDL的一部分.您可以定义诸如验证之类的东西.但是对于域,唯一约束不再那么笼统,它是数据库级别的约束,必须在其中应用.
As far as I know, constraints are not part of JDL in a general manner. You can define such things as validations. But as for the Domain, the unique constraint is not that general anymore, it is a database level constraint, where it has to be applied.
为此,JHipster包括Liquibase.因此,您可以找到更改日志,在"src/main/resources/config/liquibase"中定义实体约束,然后添加
For this, JHipster includes Liquibase. So you can find the changelog, defining the entity constraints in "src/main/resources/config/liquibase", and add a
<addUniqueConstraint tableName="airplane_model_seat" columnNames="seat_no, model_id_id"/>
更改日志.
如果您已经使用h2磁盘持久性数据库启动了应用程序,请先mvn clean
/./gradlew clean
,然后再重新启动应用程序.
If you already started your application used h2 disk persistent databse, make a mvn clean
/ ./gradlew clean
before starting your app again.
这篇关于如何在JDL-Studio中为2列创建唯一约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!