Avoid having constraint created by hibernate without having access to the entity

I have an entity where I cant have access to modify a wrong unique=true into the column definition

@Embeddable
class SomePk{
    @Column(name="PERSON_ID", unique=true, nullable=false, precision=15)
	public long getPersonId() {
		return this.personId;
	}
}

Using DB-Rider/DBUnit with Hibernate and Spring into JUnitTests the tables and constraints are auto-created before inserts are done according to DB-rider principles.

Am looking for a way of either avoid this constraint creation. Having something like com.my.package.SomePk.PERSON_ID:forceUnique=false

Looked into insert listeners, as well as hibernate reverse engineering config but didnt find a way yet…

That’s not really possible. You should think about using a schema management tool like Liquibase or Flyway, which will allow you to control your exact schema.

1 Like