Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase , how to add a group of fields like primary key?

I have an entity with a group of fields in primary key. Like this :

@Entity
@Table(name = "pv_object")
@NamedQuery(name = "PreviousObject.findAll", query = "SELECT p FROM PreviousObject p")
public class PreviousObject implements Serializable {

    @EmbeddedId
    private FieldsDTO fieldsdto; 

    //
}

FieldsDTO class contains 2 String and 2 Integer.

I have and I use Liquidbase on my project in a XML file, but, I don't know how to represent this ID of 4 fields in liquidbase.

Thanks for your help :)

like image 458
Fizik26 Avatar asked Jan 30 '19 12:01

Fizik26


2 Answers

In <addPrimaryKey you can configure columnNames by all your columns that compose your primary key

<changeSet author="liquibase-docs" id="addPrimaryKey-example">
    <addPrimaryKey
        columnNames="id, name"
        constraintName="pk_person"
        schemaName="public"
        tableName="person"
        tablespace="A String"/>
</changeSet>
like image 168
ValerioMC Avatar answered Oct 14 '22 03:10

ValerioMC


Assign the same primaryKeyName to them.

    <createTable tableName="pv_object">
        <column name="x" type="bigint">
            <constraints nullable="false" primaryKey="true" primaryKeyName="PK_pv_object"/>
        </column>
        <column name="y" type="bigint">
            <constraints nullable="false" primaryKey="true" primaryKeyName="PK_pv_object"/>
        </column>
    </createTable>
like image 33
M.F Avatar answered Oct 14 '22 02:10

M.F