Fizik26
Fizik26

Reputation: 839

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 :)

Upvotes: 14

Views: 25186

Answers (3)

Bartek K
Bartek K

Reputation: 73

or add separately

<addPrimaryKey tableName="REPRESENTATIVE" columnNames="REPRESENTED_USER_ID,REPRESENTATIVE_ID"
                constraintName="REPRESENTED_REPRESENTATIVE_PK" />

Upvotes: 1

ValerioMC
ValerioMC

Reputation: 3166

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>

Upvotes: 24

M.F
M.F

Reputation: 443

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>

Upvotes: 17

Related Questions