Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not picking up unique JPA constraints #483

Closed
jasperjanuar opened this issue Apr 24, 2023 · 1 comment
Closed

Not picking up unique JPA constraints #483

jasperjanuar opened this issue Apr 24, 2023 · 1 comment

Comments

@jasperjanuar
Copy link

jasperjanuar commented Apr 24, 2023

Description
Running a diffChangelog does not pick up on JPA unique constraints

Versions
liquibase-core 4.21.1
liquibase-hibernate6 4.21.1
Spring boot 3.0.5
org.postgresql:postgresql 42.6.0
java 17

liquibase.properties

liquibase.hub.mode=off
url=jdbc:postgresql://localhost:5432
username=username
password=pass
driver=org.postgresql.Driver
changelogFile=src/main/resources/db/db.changelog-master.yml
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com\
  ?dialect=org.hibernate.dialect.PostgreSQLDialect\
  &hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy\
  &hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

Entities
Test

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

@Entity
@Table(uniqueConstraints = {
    @UniqueConstraint(columnNames = {"givenName", "middleName", "surName"})
})
public class Test extends BaseEntity {

  @Column(unique = true)
  private String givenName;
  private String middleName;
  private String surName;
}

BaseEntity

import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Version;
import java.time.Instant;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;


@SuperBuilder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@MappedSuperclass
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class BaseEntity {

  @Column(updatable = false, nullable = false)
  @GeneratedValue
  @Id
  @EqualsAndHashCode.Include
  UUID id;

  @Version
  private Long version;

  @CreationTimestamp
  @Column(nullable = false, updatable = false, columnDefinition = "TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP")
  private Instant created;

  @UpdateTimestamp
  @Column(nullable = false, updatable = true, columnDefinition = "TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP")
  private Instant updated;
}

Output yaml

databaseChangeLog:
- changeSet:
    id: 1682344414526-28
    author: user (generated)
    changes:
    - createTable:
        columns:
        - column:
            constraints:
              nullable: false
              primaryKey: true
              primaryKeyName: testPK
            name: id
            type: BYTEA
        - column:
            constraints:
              nullable: false
            defaultValueComputed: CURRENT_TIMESTAMP
            name: created
            type: TIMESTAMP WITH TIME ZONE
        - column:
            constraints:
              nullable: false
            defaultValueComputed: CURRENT_TIMESTAMP
            name: updated
            type: TIMESTAMP WITH TIME ZONE
        - column:
            name: version
            type: BIGINT
        - column:
            name: given_name
            type: VARCHAR(255)
        - column:
            name: middle_name
            type: VARCHAR(255)
        - column:
            name: sur_name
            type: VARCHAR(255)
        tableName: test

Expected
I would expect 2 unique constraints on given_name column and the combination of "given_name", "middle_name", "sur_name"
Additional, column id of type UUID, is assigned to 'bytea' - I would have expected UUID

@wslaghekke
Copy link

wslaghekke commented Apr 24, 2023

Fixed in #480 , not released yet but will be fixed when that fix releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants