membersound
membersound

Reputation: 86885

How to set the constraint name of a @OneToOne mapping?

@OneToOne
private AnyEntity entity;

hibernate will create a mapping as follows:

CONSTRAINT fk_kcn86scsc0pasdasdngmrqc5i0 FOREIGN KEY (text_id)
 REFERENCES some_table (id) MATCH SIMPLE
 ON UPDATE NO ACTION ON DELETE NO ACTION

Question: how can I set the constraint name explicit from within java?

I cannot introduce a bidirectional mapping, as the AnyEntity class will be used in multiple other @Entity classes.

Upvotes: 0

Views: 346

Answers (1)

prab2112
prab2112

Reputation: 1034

You can use @ForeignKey annotation.

@ForeignKey(name="constraint_name")

Upvotes: 3

Related Questions