Similar to HHH-4414 i need the correct constraint name. This is my source:
{noformat} @Entity @Table(name = Tables.MENUPOINT, uniqueConstraints = { @UniqueConstraint(name = Menupoint.UNIQUE_ORDER, columnNames = { Menupoint.SQL_ORDER }) }) @SuppressWarnings("serial") | public class Menupoint implements Serializable { | public static final String UNIQUE_ORDER = "ORDER_KEY"; <---------------------(not used) public static final String PROP_ORDER = "order";
public static final String SQL_ORDER = "\"order\""; .... {noformat}
This is what reveng generates me:
{noformat}CREATE TABLE public."MENUPOINT" ( id BIGINT NOT NULL, "order" INTEGER, version BIGINT, parent_fk BIGINT, CONSTRAINT "MENUPOINT_order_key" UNIQUE("order"), CONSTRAINT "MENUPOINT_pkey" PRIMARY KEY(id), CONSTRAINT fk4c04d371bbfb7375 FOREIGN KEY (parent_fk) REFERENCES public."MENUPOINT"(id) ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE ) WITH (oids = false); {noformat}
As you see, the constraint-name in the Entity (ORDER_KEY) differs from the constraint-name of the table (MENUPOINT_order_key).
Why is this important?
I need to swap the "order" in a transaction. Therefore i make the constraint deferrable and deferre them in the Transaction using: {{entityManager.createNativeQuery("SET CONSTRAINTS " + Menupoint.UNIQUE_ORDER + " DEFERRED").executeUpdate();}}
I hardly know that jpa/hibernate does not support deferrable constraints but this is not a feature-request for supporting deferrables, its a bug-report for a wrong creation of the database. |
|