How to create unique constraint for 2 columns in JDL-Studio?

北城余情 提交于 2019-12-21 05:15:22

问题


I have following entity configuration:

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    |                |
+-------------+--------------+------+-----+---------+----------------+

How can I apply unique constraint for (seat_no, model_id_id) column combination in JDL-Studio?

If this is not possible in JDL-Studioi is there any other to accomplish this?


回答1:


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.

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"/>

to that changelog.

If you already started your application used h2 disk persistent databse, make a mvn clean / ./gradlew clean before starting your app again.



来源:https://stackoverflow.com/questions/39315986/how-to-create-unique-constraint-for-2-columns-in-jdl-studio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!